instead of doing that, you should save the images as the timestamp of when they are uploaded. that way you can have cron run a script to just go thru and delete all images that are older than x days or hours, since there is no absolute way to have files deleted when a session ends or when a user closes the browser. you could use a javascript onUnload event to pop a new window to a script to delete it, but some users will have popup blockers or close it before it loads.
so you will have images like 1085779870.jpg and the cron will list all the files in a dir and just look at the timestamp part by exploding out the . and calculate the age and delete if necessary. hopefully you understood all that 😉