Today, I learned about PHP file operation commands, including fopen, fwrite, fclose, and is_writable, but in use, in many cases, problems such as file does not exist, no permission to write, opening failure, and writing failure may occur. How to accurately control and judge the problems becomes a "small problem" in PHP ", the following statements are extracted from the book.
<? Php
$ 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 "the file $ filename is successfully written ";
Fclose ($ handle );
} Else {
Echo "File $ filename cannot be written ";
}
?>
Programming section: Pay attention to the symbols of Chinese and English input methods, especially the ";" after Chinese! Green Channel: Please follow my favorites to contact me