views:

36

answers:

3

When I use a form to upload a file, it gives me the 'name' and 'tmp_name' and you're supposed to move the file from its temporary location in order to keep it. But how long does the file stay on the server before it gets deleted? Is it stored there permanently until you manually clean up your folders, or does it get deleted once the PHP script it was submitted too is finished running? My form spans over multiple pages and I wanted to just process everything at the end rather than processing parts after each page of the form is completed. The upload is in step 3 of 5 so I was wondering if I saved the uploaded file information from step 3, if the file would still be there when the form is finished after step 5.

+2  A: 

it get deleted once the PHP script it was submitted too is finished running

so, you can either make file upload as last step or implement your own garbage collector for the unfinished forms.

Col. Shrapnel
+1  A: 

It depends on the tmp upload folder. If it is the tmp directory, you can't really trust it to live to step 5. If you control the upload folder, then you could reliably trust it to live to step 5. You can set the upload path with upload_tmp_dir

Jason McCreary
Looks good to me. Only thing I can foresee is that it will need some cleaning up every now and then if users don't finish the form.
Patrick
-1 file at tmp_name is destroyed at the end of the request. See Marc B's answer.
timdev
@timdev, thanks for the correction.
Jason McCreary
+1  A: 

Unless PHP dies a horrible flaming death, or you take steps to preserve the file, it'll be auto-killed by PHP when the script exits. If you need to preserve it through a multi-stage form, you'll have to move it somewhere safe, and then keep track of it (hidden form fields, session, database, etc...) and implement your own cleanup system to handle orphaned files from abandoned forms.

Marc B