删除临时文件php

I have a page that which add new User.

The user have file attachment option.

I created a temporary table and directory to upload file and track the user data.

The problem is the user is not yet added ,so i cannot save these files under the contact.

what i am doing is saving the files and tracking using a temp table and once the user is added moving those files under that user.

Assume that user uploaded the files and closed the page without adding user.

Then how can i delete the temp files and table values ?

can i use the browser close event ? alternatively is there anyway to do this in php [because i am new in php] ?

I am using Codeignitor - it will be very helpful if i get answer respective to CI.

Thanks in advance.

Browser close events are highly unreliable. When you add the user to the temp table, add a timestamp as well. Run a nightly cron job that prunes all old values from the DB and files from the filesystem.

xbonez's cron job idea would just work fine - but just another suggestion -

As you mentioned you add a row in temp table for every file uploaded so when this happens drop/update a cookie with row ID. So if the user comes back to complete the registration you could check if this cookie exists - if yes you can show already uploaded files (with option to remove). You can try $this->encrypt->encode() and decode functions provided by encryption class to encode and decode the cookie value AND/OR some other checks to ensure integrity of cookie data. http://codeigniter.com/user_guide/libraries/encryption.html Delete files older than, say week.