delete file automatically after session ends

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
radio86
Forum Newbie
Posts: 4
Joined: Mon Mar 01, 2010 9:01 am

delete file automatically after session ends

Post by radio86 »

hi guys,

i am new not only to this forum but to php too. I have allowed the user to upload file n each file name is session id. n i store the filename in $_SESSION variable but when the user signs out or closes their browser, i want php to delete that file which was uploaded.

presently my solution to this problem is:

i run jquery to refresh a div after every 1 mseconds n that div is refering to php file which checks if user has logged out then delete file else dont...

but my bad luck...this is not working...i thought might as well see the experts, can you guys please suggest whether i can do this or not in php.

many thanks in advance
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: delete file automatically after session ends

Post by tr0gd0rr »

Since the web is stateless, you can't know when a user closes their browser. Why do you need to delete the file? If it is a disk space issue, simply run a clean-up script on a regular basis; it could delete any files that are older than a certain date.
Post Reply