Home > Backend Development > PHP Tutorial > Judgment and execution of PHP file opening, closing, writing_PHP tutorial

Judgment and execution of PHP file opening, closing, writing_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:43:42
Original
852 people have browsed it

Today I learned the file operation commands of PHP, including fopen, fwrite, fclose, and is_writable. However, in use, many times you may encounter files that do not exist, do not have permission to write, open fails, write How to accurately control and judge various problems such as entry failure has become a "small problem" in PHP. The following is a sentence excerpted from the book.

$filename = "html/cache.txt";
$contents = "I am Zhang Bin";
if(is_writable($filename) ){
if(($handle = fopen($filename,"a") )== ​​false){
echo "Failed to write file $filename";
exit();
}
if(fwrite($handle,$contents) == false){
echo "Failed to write file $filename";
exit();
}
echo "Write to file $filename successful";

fclose($handle);
}else{
echo "The file $filename cannot be written";
}
?>

Judgment and execution of PHP file opening, closing, writing_PHP tutorial

Programming section: Pay attention to the symbols of Chinese and English input methods, especially the ";" after Chinese!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478825.htmlTechArticleToday I learned the file operation commands of PHP, involving fopen, fwrite, fclose, is_writable, but in use, many Sometimes you may encounter files that do not exist, do not have permission to write, fail to open,...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template