Php create a file if not exists
问题 I try to create files and write the contents dynamically. Below is my code. $sites = realpath(dirname(__FILE__)).'/'; $newfile = $sites.$filnme_epub.".js"; if (file_exists($newfile)) { $fh = fopen($newfile, 'a'); fwrite($fh, 'd'); } else { echo "sfaf"; $fh = fopen($newfile, 'wb'); fwrite($fh, 'd'); } fclose($fh); chmod($newfile, 0777); // echo (is_writable($filnme_epub.".js")) ? 'writable' : 'not writable'; echo (is_readable($filnme_epub.".js")) ? 'readable' : 'not readable'; die; However, it