2

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 '15 at 14:47
1

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.

0

Do you write to 2 different tables like...

tblTmpUpload
id
file_path
timestamp

tblUpload
id
file_path
otherstuff
timestamp

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, privacy policy and cookie policy

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