简体   繁体   中英

move_uploaded_file not working

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 ?

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)

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM