I want to upload an image on a remote host (Everything is ok locally).
I’ve used the code below like my other previous projects to do it:
if (move_uploaded_file($_FILES["scan"]["tmp_name"], 'images/scans/1.jpg')) {
chmod ('images/scans/1.jpg','0644');
}
But every time I run this code in the internet, I get an error:
Warning: move_uploaded_file(images/profile/Mordent.jpg) [function.move-uploaded-file]:
failed to open stream: Permission denied in …
I have to change scans directory permission to 0777 and then I can upload images. Otherwise I can not. It’s very strange for me. I’ve used this code in many times in different projects and I had not any problem with it.
images/scans/must be writable by the web server user, and should not need to be0777, which is world-writable. First,imagesmust be readable by the web server user, having a5in the last position (like0755). Thescansdirectory must be owned by the web server user or writable by it. It is preferable to have it owned by the web server user, where its permissions can also be0755.