What would be the best way of going about this.
I am uploading files to a directory and I would like to have a script that automatically deletes them after 72 hours.
Thanks for the help.
What would be the best way of going about this.
I am uploading files to a directory and I would like to have a script that automatically deletes them after 72 hours.
Thanks for the help.
Setup a DB that stores the filename and uploaded time. If the server is *nix based, Then create an hourly CRON job that checks the current time, and deletes all files with times that are 72 hours old or older...
maybe something like this
untested use at your own risk
#directory to scan
$Directory = "some_dir"
#time in seconds
$time = "259200"
if ($files = opendir($Directory)){
while (false !== ($currentFile = readdir($files))){
#skip "." and ".."
if ($currentFile != "." && $currentFile != "..") {
#get current time (unix epoch)
$currentTime = date(U);
#get file times (remember, it's epoch)
$fileTime = date(filemtime("$Directory/$currentFile"));
#subtract to come up with the difference
$remainder = $currentTime - $fileTime;
if ($remainder > $time){
$cleanup = unlink("$Directory/$currentFile");
}//end if
}//end if
}//end while
}//end if
just use cron like TheDefender said. Butthead script only work if the page still open.