Skip to content

Instantly share code, notes, and snippets.

@t0mtaylor
Created June 14, 2014 15:23
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 t0mtaylor/9a450f3eb80c0d1c9b4d to your computer and use it in GitHub Desktop.
Save t0mtaylor/9a450f3eb80c0d1c9b4d to your computer and use it in GitHub Desktop.
<?
chdir( dirname ( realpath(__DIR__) ) );
chdir( 'tmp/' );
$days = 0;
$hours = 3;
$root = getcwd()."/cache/";
$paths = array($root."",$root."remote/");
$filetypes_to_delete = array("gif","jpg","jpeg","png","bmp");
foreach ($paths as $path)
{
print $path . "\n";
if ($handle = opendir($path))
{
if($handle)
{
while (false !== ($file = readdir($handle)))
{
// Check the file we're doing is actually a file
if (is_file($path.$file))
{
$file_info = pathinfo($path.$file);
if (isset($file_info['extension']) && in_array(strtolower($file_info['extension']), $filetypes_to_delete))
{
// Check if the file is older than X days X hours old
if (filemtime($path.$file) < ( time() - ( $days * $hours * 60 * 60 ) ) )
{
// Do the deletion
unlink($path.$file);
}
}
}
}
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment