Skip to content

Instantly share code, notes, and snippets.

@rochow
Created June 24, 2018 01:37
Show Gist options
  • Save rochow/5c6f7a8823c6d5493160e7073be99d63 to your computer and use it in GitHub Desktop.
Save rochow/5c6f7a8823c6d5493160e7073be99d63 to your computer and use it in GitHub Desktop.
Simple cleanup script to remove files in a directory older than X days
<?php
$files = glob("*");
$time = time();
$ignore = array('cleanup.php','.ftpquota','index.html','robots.txt');
foreach($files as $file) {
if(is_file($file) && !in_array($file,$ignore)) {
if($time - filemtime($file) >= 60*60*24*30) { // 30 days
unlink($file);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment