This is more of a conceptual question and not about the underlying programming technique.
When I am in the process of creating a new record (say an Add Record screen), the record ID isn’t available to me yet. The same screen has an option of uploading a picture too, using SWFUpload – which means the picture gets uploaded immediately.
Since the record id isn’t available yet, there’s no way to associate this particular picture with a record in the DB till I’ve hit the Save button.
Now suppose, after uploading the picture I navigate away from the Add record screen leaving an orphaned picture file on the server.
I can come back to the Add record screen and keep doing this on and on… and eat up a sizable chunk of the server space with unlinked / unused images.
How would you tackle this issue? What flow of logic should be enforced here?
One option (which I’m experimenting with right now), is to store the uploaded images in a tmp folder and moving them out and placing them in another proper folder once the record has been created (with a link the the picture in it’s final resting place). And then, run nightly cron jobs to clear off the leftovers from the tmp folder.
Any other brighter and elegant approaches to this?
Thanks,
m^e
Kinda old question so you probably figured it out but this is how I go around it:
the value is 0, if so create a new
Guid for this image and return it to
your swfupload and set your hfImgGuid with this value. Also store the Guid in the user Session.
I hope you get the idea, it can get very complex if you want to do it right and there are many ways to do it, but an ajax-style upload looks nice indeed and professional pages are hardly to be found without it.