tags:

views:

64

answers:

3

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phptMeFd4' to './photogallery/4bf2806a0d80c4ad68aa5e4e20dscn6842.jpg' in /some path/addsplashphoto.php on line 49

am trying to upload photo to a destination folder in my server but each and every time an error like above is appearing..same code is working quite well at localhost(i have set changed the file permissions of my server folder but still have the same problem )

somebody please tell me the reason of this error...

A: 

Make sure that:

  • You are specifying the correct path
  • Folder has write permissions, chmode to 755
  • You have specified the encoding type attribute in the form set to multi-data
  • Try prefixing the path with $_SERVER['DOCUMENT_ROOT']
Sarfraz
`0755` wont' work if Apache/PHP runs as `nobody` or similar.
Alix Axel
@Alix Axel: Then suggest the alternative please. Thanks :)
Sarfraz
@Sarfraz: Sure http://gist.github.com/405019 :)
Alix Axel
@Alix Too wordy way to say "777". And exceptionally useless code.
Col. Shrapnel
@Col. Shrapnel: can you come up with a shorter function that does the same?
Alix Axel
@Alix yeah sure. It wouldn't try to chmod another user's files in vain.
Col. Shrapnel
@Alix Axel: That's great share, thanks :)
Sarfraz
@Col. Shrapnel: You lost me there... What? @Sarfraz: No problem. =)
Alix Axel
@Col. Shrapnel: I wouldn't call it "exceptionally useless code", `0666/0777` doesn't work under all circumstances: if you run SuPHP and/or a PHP hardened patch a `0777` will trigger a 5xx server error. The function takes that into consideration and automatically chooses the best possible writable permission for the given file or folder, so that you don't end up with undeleatable files (like uploads).
Alix Axel
@Sarfraz: I was replying to both of you on the same comment. I didn't understood what Col. Shrapnel was trying to say and now I don't understand you (what do you want me to elaborate?) lol..
Alix Axel
@Alix ah I see now. You've gone so far from the initial question and talking now of the uploaded files. Sure you can make it readable for the ftp user, but it doesn't really matter. As for the initial question, "how to make a directory writable under nobody", this function is useless, and the only solution is FTP
Col. Shrapnel
@Col. Shrapnel: Not only uploaded files but any file/folder created with PHP for that matter, I coded the function for the exact purpose of having a portable way of chmod'ing files and folders so that they are always writable and don't cause server errors, and it has proved to be a *exceptionally useful* piece of code so far. As for the *original* question of "how to make a directory writable under nobody" - I can't read that anywhere but we can further discuss that if you want to. :)
Alix Axel
@Alix well. What was your first comment for? Isn't it was for the OP file moving problem?
Col. Shrapnel
@Col. Shrapnel: Actually, no. My first comment was an addition to the answer @Sarfraz originally provided, my **second** comment (the one with the link to the function) is my **coded explanation of 4 different possible scenarios** - I could have just replied `0777` but it would be incomplete. Also, **isn't it was ...** is incorrect (is = present, was = past), the correct form is **wasn't it ...**.
Alix Axel
@Alix aha got it. It's still exceptionally useless in the OP context. And you are undoubtedly right for the rest.
Col. Shrapnel
@Col. Shrapnel: Totally agree, that was the reason I replied in a comment rather than in an answer - I'm not even half sure if the OP problem is related to file system permissions. Still, if it is, using the function right from the beginning would've solved any issues that would otherwise possibly arise.
Alix Axel
@Alix I doubt it :) If you can chmod a file, you can write it too. So, no function needed. Otherwise this function won't help. It is FTP client to use from beginning.
Col. Shrapnel
@Col. Shrapnel: It's not always like that.. I'll let you figure it out by your own. ;)
Alix Axel
@Alix I wish you had guts.
Col. Shrapnel
@Col. Shrapnel: Why? Are you feeling stupid **already**?!
Alix Axel
A: 
  • also make sure that ./photogallery dir exists.
hudolejev
yes the folder ./photogallery is there..
rag
Place some files in there. What's the output of `system('/bin/ls ./photogallery')`?
Adam Backstrom
@ Adam Backstrom it s listing all the files in that folder(photos)
rag
A: 

Try to use an absolute path instead of a relative path. For example if your code looked like:

$path = "./photogallery/4bf2806a0d80c4ad68aa5e4e20dscn6842.jpg";
move_uploaded_file($_FILES['something']['tmp_name'],$path);

change that to:

$path = dirname(__FILE__)."/photogallery/4bf2806a0d80c4ad68aa5e4e20dscn6842.jpg";
move_uploaded_file($_FILES['something']['tmp_name'],$path);

Obviously, change the path to be the correct path :-)

Josh