Skip to content

Instantly share code, notes, and snippets.

@rochow
Created August 1, 2022 01:53
Show Gist options
  • Save rochow/7c956544696fcd19718ea83983639b0a to your computer and use it in GitHub Desktop.
Save rochow/7c956544696fcd19718ea83983639b0a to your computer and use it in GitHub Desktop.
Cleanup files in a directory based on time
<?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