I have a form on my site to submit posts, it features multiple file upload tool (Mini Ajax File Upload Form) which submits files to server as they are added (before actual post submission) and server then stores them in temp dir. Once article has been submitted, all associated files are stored to uploads dir and temp dir is cleared.

How should I clean temp dir from files left after posts where files were added but which were never submitted? Should I do it just from time to time using, say, cron script or is it better to do whenever site scripts run?

Post submission must be anonymous (with captcha or some more difficult verification), so I'm concerned with server being stuffed with files from abandoned forms.

  • 3
    I would write a script that deletes files based on mtime and run it in a cron once a day.
    – Octopus
    May 5, 2015 at 14:47

2 Answers 2


I'd go in reverse order.

Make file submission happen last then use crontab to delete garbage data at frequent intervals.

If the data being submitted is small enough, then use PHP sessions or cookies to store the basic information then when the files are submitted, then store the basic info from the cookies or sessions to the database and then you won't have to worry about deleting files.


Do you write to 2 different tables like...



If so, you could query the tblTmpUpload and look for files w/ a timestamp more than 24 hours old and remove the file based on file path stored.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.