cleanup.php 671 B

123456789101112131415161718192021
  1. <?php
  2. define('CACHE_DIR', __DIR__ . '/../public/cache');
  3. function deleteDir($dir) {
  4. if (!is_dir($dir)) return;
  5. $files = array_diff(scandir($dir), ['.', '..']);
  6. foreach ($files as $file) {
  7. (is_dir("$dir/$file")) ? deleteDir("$dir/$file") : unlink("$dir/$file");
  8. }
  9. rmdir($dir);
  10. }
  11. foreach (['stage1', 'stage2', 'stage3'] as $stage) {
  12. $stageDir = CACHE_DIR . '/' . $stage;
  13. if (!is_dir($stageDir)) continue;
  14. foreach (scandir($stageDir) as $folder) {
  15. if ($folder == '.' || $folder == '..') continue;
  16. $path = "$stageDir/$folder";
  17. if (is_dir($path) && (time() - filemtime($path) > 600)) deleteDir($path);
  18. }
  19. }