Skip to content

Instantly share code, notes, and snippets.

@a1phanumeric
Created December 14, 2012 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a1phanumeric/4284074 to your computer and use it in GitHub Desktop.
Save a1phanumeric/4284074 to your computer and use it in GitHub Desktop.
Removes files older than one day
<?php
// Removes files older than a day
$dir = '/path/to/dir';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
$filelastmodified = filemtime($dir . '/' . $file);
$filetype = filetype($dir . '/' . $file);
if($filetype != 'file') continue;
if((time() - $filelastmodified) > 24*3600){
unlink($dir . '/' . $file);
}
}
closedir($handle);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment