views:

139

answers:

1

Hi, 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.

+5  A: 

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.

kemp
Thanks. That saved a lot of time. Actually i was using image upload inside a form. So user fills in the details, and uploads a image. But only when user hits submit, the details along with the image are submitted. Do you know any way how i can achieve this.?
noobcode
You can still access the other fields just using $_POST (given that your form method is POST).
Lex
I'm not sure I understand what exactly you need to do.
kemp
@idrish: The image is probably uploaded through AJAX, then deleted after a certain amount of time if not accompanied by the remaining information.
Johannes Gorset
One more question/ I am looking for something like in gmail image upload. ANy pointers? thanks
noobcode