views:

74

answers:

4

I'm uploading files via JS and storing the temp path in the session. Than i use the following code to move the files.

if(move_uploaded_file($_SESSION['temp_img'][$key]['path'], $dest.$bigimg)){

$dest and $bigimg are defined earlier in the script with the id from the database.

Any Ideas or alternatives ?

A: 

What is the output of $_SESSION['temp_img'][$key]['path'], also do you have permission to write to the web directory your placing the files. You may need to set it to 777 for some hosts to allow the webserver to write there.

Mech Software
since he is uploaded to a different script, move_uploaded_file is failing since no file was actually posted to that script
MANCHUCK
/tmp/phpbvWPqW -the output from sessionand the permissions are set
Ross
+1  A: 

move_uploaded_file checks that a file has been uploaded to that page. You are actually uploading the file to a different PHP script then storing in a session. Instead of using move_upload_file use rename.

MANCHUCK
That shows the issue however it still won't work. If he doesn't call `move_uploaded_file` before the request finishes the file will be deleted.
Josh
A: 

Check the File Permissions for the Folder where you are uploading.

Shyju
+2  A: 

MANCHUCK's answer was close but not quite there. You must call move_uploaded_file within the script where the file was uploaded. You cannot do what you're doing, that is, "storing temp path in the session" because that path is only valid for one request.

From the PHP manual:

The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.

(Emphasis mine)

Josh