I am learning PHP and trying to upload a file using this code :
$destination = "uploads/".$_FILES['userfile']['name'];
move_uploaded_file($_FILES['userfile']['tmp_name'], $destination);
but I am faced with
failed to open stream: Permission denied
I can change the permissions for the “uploads” directory to be writable by everybody, but of course this is bad practice.
The folder permissions are :
drwxr-xr-x 2 loai loai 4096 Dec 30 12:44 uploads
and running ps aux | grep httpd yields
loai 6728 0.0 0.0 4368 832 pts/1 S+ 18:37 0:00 grep --colour=auto httpd
so shouldn’t the apache process be able to write in the given directory ?
Thanks
First, as noted in comments to the question, your
psoutput is showing thegrepprocess itself, nothttpdprocess (or whatever your web server is). So that probably means that your web server is running as a different user, not asloai. Either change ownership of theuploadsfolder or make it group-writable and then add web server’s user to the appropriate group