-1

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.

Mohammad Saberi
  • 12,864
  • 27
  • 75
  • 127
  • Perhaps this question can help you http://stackoverflow.com/questions/8776348/php-script-not-processing – fkerber Jan 08 '12 at 12:31
  • `chmod()` takes an integer, supplying an integer expressed as an octal held in a string is liable to produce unexpected results. For absolute clarity, you should either pass a decimal integer (as a string if desired/required) or remove the quotes surrounding your octal. I know this is not problem here, because the error you get happens before you reach the `chmod()` but it's still worth noting. – DaveRandom Jan 08 '12 at 12:46
  • I did your suggestion and removed quotes. Thank you. But as you said, the problem is still remained – Mohammad Saberi Jan 08 '12 at 16:48

2 Answers2

2

images/scans/ must be writable by the web server user, and should not need to be 0777, which is world-writable. First, images must be readable by the web server user, having a 5 in the last position (like 0755). The scans directory 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 be 0755.

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
0

According to php.net:

Note: This function will not work on remote files as the file to be examined must be accessible via the server's filesystem.

Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
  • 2
    I believe when the OP says "remote host" he means "production server", as opposed to his own computer. – JJJ Jan 08 '12 at 12:35