Created
December 14, 2012 09:39
-
-
Save a1phanumeric/4284074 to your computer and use it in GitHub Desktop.
Removes files older than one day
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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