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
The image can be uploaded directly to the database without storing on the server. But it will increase the database size and web page load time. So, it's always a good idea to upload images to the server and store file names in the database.
Kinda old question so you probably figured it out but this is how I go around it:
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.
you could eliminate at least part of the problem by storing paths to all uploaded items in a cookie (or cookies, if using different browsers) on the client computer.
alternatively, don't use SWFUpload, use plain-old HTML "input type=file" upload, and enforce record creation before addition of an associated photo. that would arguably be the cleanest solution to a potentially messy problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With