3

I can't seem to find clarification. I have 7 steps and the second one is to upload a file. The problem I am having is that on the final step when I finalize the form and try and access the temp file it says "Could not access file: ..." (saved in the default tmp folder).

Other multi-step tutorials say to keep it in a temp folder and then move to the appropriate folder when complete. So do they mean I move it from the default temp folder into a temp folder I manage and then when they complete the form move it again to a final folder?

user162941
  • 101
  • 2
  • 3

2 Answers2

2

So do they mean I move it from the default temp folder into a temp folder I manage and then when they complete the form move it again to a final folder?

Yes, exactly. You do the first move on the request that receives the files, because when that request is finished PHP would delete them if they still exist.

See move_uploaded_fileDocs and Handling File Uploads.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • Alright, thanks for the clarification. Just a follow-up, how can I properly manage the temp folder like PHP does? If people stop after uploading and the file sits in the temp folder do I create a script to delete all files that are past a certain date/time? If so, do I run this when I upload files? – user162941 Oct 05 '11 at 17:15
  • I would create a *janitor job* in form of .sh script that get's executed via cron. It will keep the folder clean independent to your website. See a related question for some useful hints: [Session Files Not Getting Cleaned Up](http://stackoverflow.com/questions/6845316/session-files-not-getting-cleaned-up/6845361#6845361) – hakre Oct 05 '11 at 17:40
0

With "temp folder" they don't mean /temp.

After the upload, you should actually save the file in some folder, maybe with the user's session id as name. Then, with the last step, you should move that file to its definitive location.

Temp files (like, actual temporary file) are destroyed once the program who created them exits (that means usually, in php, after the next output page is sent to the client).

cbrandolino
  • 5,873
  • 2
  • 19
  • 27