I am having problems with a picture uploading script.
I know there are hundreds of the same questions, but I haven't found the one that would be work for me.
$upload_dir = "images/postcards/";
chmod($upload_dir, 777);
if (is_writable($upload_dir)) {
echo 'The file is writable';
} else {
echo 'The file is not writable';
}
This always returns that the file is "not writable"
I tried setting chmod
to 0777
and -rwxrwxrwx
. But result was always the same. Any Ideas?
I was having similar troubles using chmod, although the file was owned by apache:apache (webserver user). In my case SELinux was getting in the way, disabling it made this clear:
And the chmod works. Now on to figuring out how to make a SELinux exception for this case... (and don't forget to enable SELinux, of course)
First , open PHP error_report by adding two line on top of your code, see if there is a error coming from chmod:
Make sure your WebServer has the permission to that directory, my guess is the WebServer don't have permission.
The directory must be owned by the user invoking the script (typically
www-data
,apache
orhttpd
if you're running the script in a apache/*NIX setup). A user can't set 777 permissions on directories it doesn't own.See the note on the chmod() manual:
I already had the same problem you can change the file's permission by this code :
I didn't run this code but I think it's Ok and it will help you. tell me if your problems resolved.