Chmod 666 and access denied for getimagesize
-
22-10-2019 - |
Question
First of all, this is not a duplicate of : Permission denied on getimagesize
I got following code, where I sat an chmod
for the image, and then I wan't to get it's size.
@chmod($path."/".$filename, '0666');
getimagesize($path . "/" . $filename);
But if I set a chmod, I'm receiving this error message:
failed to open stream: Permission denied in[...]
What is the problem? All files and the directory has the same group and owner - www-data
.
Solution
Actually do you really need to chmod before getimagesize?
if so, maybe u can try putting umask before chmod. something like this?
$old = umask(0);
chmod($path,0777);
umask($old);
OTHER TIPS
Try putting a / before path. Not sure about php, but I know python wont add the initial / to certain path operations, so it may be looking for a relative path instad of absolute:
@chmod("/". $path."/".$filename, '0666');
getimagesize("/". $path . "/" . $filename);
First of all, chmod
won't succeed (permission will be denied; maybe the error you get is from chmod?) if www-data
(assuming that's the user of your webserver) doesn't have write access to the directory $path
. Ensure www-data
has read-permission to all parent dirs of $path
and write-permission to $path
.
Also, ensure that you use absolute paths, both in chmod
and getimagesize
.