views:

269

answers:

3

I seem to have a bizarre error I just can't quite figure out. My website was working on one server, but when I transferred it to a new one it stopped working. I believe I've narrowed the error down to this line of code:

$ret = move_uploaded_file($tmp_name, $orig_path);

This is executed through an AJAX call so it's a little bit tricky to debug, but the script can send back an error code and then my JavaScript will alert it. So, I've wrapped it in two of these debug statements:

echo json_encode(array(

    'success' => false,

    'errno' => $tmp_name.' -> '.$orig_path,

));

exit;



$ret = move_uploaded_file($tmp_name, $orig_path);



echo json_encode(array(

    'success' => false,

    'errno' => 'no error',

));

exit;

The first one works fine and spits out something like:

error /tmp/phpk3RICU -> /home/username/Websites/website/photos/o/2-4a3354dd017a9.jpg

Perhaps I'm a bit of a linux noob, but I can't actually find /tmp/phpk3RICU on my system (is it deleted as soon as the script exits or what?). More on that in a sec though.

If I delete the first debug check and let move_uploaded_file run, the 2nd debug check never seems to get executed, which leads me to believe move_uploaded_file is hanging.

If instead of using $tmp_name I use a file I know doesn't exist, then the 2nd check DOES get executed. So... it seems like it just doesn't want to move that tmp file, but it's not reporting an error.

I'm running a fresh install of the LAMP stack on my Unbutu machine, installed through apt-get... let me know if you need more info.

Oh.. and don't know if it's relevant, but the file gets uploaded through flash.

+1  A: 

Do you upload the file via the AJAX call? Uploaded files are deleted as soon as the script you uploaded them to finishes executing - that's why you can't find it in /tmp.

Greg
+1  A: 

Try telling PHP to spit out all errors:

error_reporting(E_ALL);

It could be a configuration discrepancy that is breaking it on one of your servers. From the move_uploaded_file() manual page:

Note: move_uploaded_file() is both safe mode and open_basedir aware. However, restrictions are placed only on the destination path as to allow the moving of uploaded files in which filename may conflict with such restrictions. move_uploaded_file() ensures the safety of this operation by allowing only those files uploaded through PHP to be moved.

karim79
A: 

Ugh. The problem was with permissions. 755 was enough on the other server, but not for this server it seems... not really sure why, I guess PHP is running under a different user? I'm not really sure how the whole permissions stuff works. What really boggles me is why mkdir and move_uploaded_file didn't fail and return false...

Mark