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