I’m working on a multi-part form that will allow for images to be uploaded. The contents of the form are saved in a SESSION. So far, this is great, since the contents get destroyed if the user decided to abandon the form before completing it.
What if they upload an image and THEN abandon the form?
What’s best practice for handling that image if the user abandons the form?
Probably just scrap it along with everything else since if they change their mind they can simply reload it again. If your form is a long process, you might offer a “save draft” feature that will preserve what is already completed until they can return and complete the process, otherwise I would just scrap everything if the form is abandoned.
If you find the form is often abandoned unintentionally for some reason, you could save contents for a limited time allowing them to return and complete the process and then scrap it after the chosen time limit has expired.
I’m trying to remember how I did this…
When an image is first uploaded it gets a temp name, once the transaction is complete it gets a permanent name. The temp name gets recycled over and over again with subsequent images so there is no need to keep track or delete anything. The last uploaded image of a completed transaction will actually exist with its permanent name and its temp name until the next image is uploaded and takes over the temp name overwriting the previous image.
Here’s an example of a temp image and then the image with its permanent name: TemporaryImage
These are both the same picture right now, but once the particular contributor uploads another image the temporary image will change. Click on each link to see the naming scheme.
crmalibu and cups provided feasible possibilities.
For me personally I don’t care about the temporary image residing on the server. It sits there forever until the user uploads another that replaces the last one. I actually show the user what they last uploaded or started to upload.
Besides the options crmalibu and cups provided if it really matters to you make the upload of an image a timed process. 1). If the form is not completed in the allowable allotted time, delete the temporary image. 2). If the form is successfully completed delete the temporary image immediately after it gets its permanent name.
if (FormCompleted){
unlink('tmp.jpg');
}elseif (TimeExpired){
unlink('tmp.jpg');
}