views:

74

answers:

2

Hey! i want to know the best solution for my problem. I have a signature generator http://www.anitard.org/siggen/siggen_stripes/ where people can upload their own images for the signature. The problem is that my storage will get full pretty fast if i dont somehow have a script that deletes the images when they are done with the signature.

What is the best solution for this?

A: 

Personally, I would have a script that runs every hour (or day, depending on volume) that checks the file's creation date and deletes it if the time is over an hour old. Realistically, users should save their images to their harddrives within 2 minutes of creating them, but you can't count on it. An hour seems like a nice compromise.

JustLoren
Ok, thanks! Maybe you could help me with that?
A: 

My initial feeling on this would be to not save the uploaded files at all, but to just delete them as soon as the image is generated. However, some browsers might request the image again when the user tries to save the image -- I know this is true with Firefox's DownloadThemAll extension, for instance. So you'll probably have to store the files for a short amount of time, like @JustLoren suggests.

A quick Google search for "php delete temp files" turns up at least one script explaining exactly how to delete files after a certain amount of time. This would not have to be run as an external script or cron job; it could merely be tacked on to the upload script, for instance.

One flaw in the given script is that someone could rapidly upload many files in a row, exceeding your disk quota. You might want to expand on the linked script by deleting any files older than the last 50 or however many. To do that, just check the count of the matched files, sort by creation time, and delete any with index greater than 50.

Mark Rushakoff