Write a file and read the file in the same way, first see if you can write: <?php $file = ' dirlist.php '; if (is_writable ($file) = = False) { Die ("I am chicken feathers, I cannot"); } ?> If you can write it, you can use the File_put_contents function to write: <?php $file = ' dirlist.php '; if (is_writable ($file) = = False) { Die (' I'm chicken feathers, I can't '); } $data = ' I am contemptible, I want '; File_put_contents ($file, $data); ?> The newly introduced function of the file_put_contents function in PHP5 (if you don't know it, use the Function_exists function to determine first) the lower version of PHP is not available, and you can use the following methods: $f = fopen ($file, ' w '); Fwrite ($f, $data); Fclose ($f); Replaced. When writing a file, you sometimes need to lock and then write: function Cache_page ($pageurl, $pagedata) { if (! $fso =fopen ($pageurl, ' W ')) { $this->warns ("Cannot open the cached file."); /trigger_error return false; } if (!flock ($fso, lock_ex)) {//LOCK_NB, exclusive lock $this->warns (' cannot lock cache file. '); /trigger_error return false; } |