Search code examples
phpfilenamestemporary-filesupload

Reusing the temporary file created by a file upload in a PHP form


regarding file uploads, I have a form through which I upload a file, I get the $temp_name = $_FILES['name']['temp_name'] and store it in a variable.

Can I then use that variable again inside move_uploaded_file("$temp_name","$location") inside another form.

Will this work??

When we upload a file, there is a temp location created on the server. How long can the temporary file be used for?

Thanks.


Solution

  • You can only use that name in the script which receives the upload since the temporary file will only last until the end of your script's execution. If you want to reuse the file you have to save it permanently.