I'm currently programming a form where users can also upload an image. The image gets uploaded to my server (to generate a preview).
If the user submits the form, everything will be good. But what if they close the editor? In this case the image will be stored on the server forever and uses needed space.
How can I handle the scenario where the image has been uploaded, but not the form has not yet been submitted?
One option I thought of is to use the unload()
function to trigger an AJAX call which deletes the image on the server if the user closes the tab:
$( window ).unload(function() {
//Make AJAX call here and pass the name of the file
});
What other options are there? How can I handle this?