Skip to content

Instantly share code, notes, and snippets.

@hedgeven
Last active October 26, 2015 07:42
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 hedgeven/f2709d0d927956527ae3 to your computer and use it in GitHub Desktop.
Save hedgeven/f2709d0d927956527ae3 to your computer and use it in GitHub Desktop.
PHP script for recursive cleaning old files
<?php
function rrmdir($dir, $t) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") {
rrmdir($dir."/".$object, $t);
} else {
if (filemtime($dir."/".$object) < time() - $t) {
unlink($dir."/".$object);
}
}
}
}
reset($objects);
}
}
rrmdir('cache', 86400);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment