PHP www-data permissions failing - but only sometimes
I am writing code to have users upload a file, then parse that file and
save both the upload and the output to the server. However, this code
works only sporadically - sometimes it will work, then a little later it
will stop or vice versa.
This is not an issue of file permissions - the folders and files in
question all are owned by a group that www-data is in and have 664
permissions (plus it works some of the time, so must have permissions).
Even when it fails, a call to is_writable() returns true right before file
operations fail.
For the first part of the code where this fails, I'm storing the file path
to copy to in $uplnm, and want to delete any previously existing data that
exists at this location. Thus I have the following two lines:
if(is_writable($uplnm)) echo "Writable<br>";
if(file_exists($uplnm)) unlink($uplnm);
A good portion of the time, I get the output:
Writable
Warning: unlink(/var/sandbox/File.txt): Permission denied in
/var/www/Upload.php on line 37
I've seen some suggestions that one should keep trying to unlink with a
loop until it works, but since I'll be running parsing later though a
shell script (which can be computationally intensive and require
intermediate read/writes) that's not an option here. I also can't change
to 666 permissions because I want to protect these folders and files from
changes by other users.
So I was wondering:
Is there a reason that php will sometimes fail to be able to make file
system changes, even with appropriate permissions?
Can I do anything to make sure that the file system changes won't fail?
No comments:
Post a Comment