Anyone have any ideas on this? I check the file with file_exists() and is_writable(), both of which return true. I set the directory and file to 777 just to be safe as well, but trying fwrite() or file_put_contents() both result in no change in the file
Here is the relevant code:
$filePath = dirname( __FILE__ ) . '/' . 'myfile.txt';
file_put_contents($filePath, "waffles are delicious");
You’ve checked the permissions of the file but also have a look at the ownership.
I’ve often seen issues where files are unpacked from archives with a uid/gid from the originating system. This is usually the case when you’ve uploaded and unpacked a zip or tar.gz installation archive of a framework, CMS or forum instead of waiting for all the files to be uploaded through FTP.
To change the file owner you’ll need to do a
chowncommand in the shell to change it to the username/group of your account. You will probably need to be root/su to do this.The
-Rmakes it recursive an applies to all files in all subdirectories.