Explain PHP Create file instance code:
- $data =date ("YMD");
- $dir = "/hom/kyle/file/$data";
- $filename = "/home/kyle/file/$data/testfile";
- $filecontent = "This is the content to be written to test space spaces";
- Determine if the folder exists or create
- if (!is_dir ($dir)) {
- mkdir ($dir, 0777);
- }
- Determine if the file exists or create
- if (!file_exists ($filename)) {$handle =fopen ($filename, W);
- if (! $handle) {
- echo Create file fail;
- Exit
- }else{
- chmod ($filename, 0777);
- }
- if (fwrite ($handle, $filecontent) = = = = FALSE) {
- echo "Cant write into $filename";
- Exit
- }
- Fclose ($handle);
- }
- ?>
http://www.bkjia.com/PHPjc/486174.html www.bkjia.com true http://www.bkjia.com/PHPjc/486174.html techarticle Explain PHP Create file instance code: PHP $data =date ("YMD"); $dir = "/hom/kyle/file/$data"; $filename = "/home/kyle/file/$data/testfile" ; $filecontent = "This is the content test to write ...