Advertisement
uzumaxy

Delete old files, PHP

Jul 13th, 2013
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.66 KB | None | 0 0
  1. ///Destroy old files from selected dir
  2. ///$dir — directory to process
  3. ///$old — time of life for one file, in seconds
  4. function destroy($dir, $old) {
  5. $mydir = opendir($dir);
  6. while($file = readdir($mydir)) {
  7.     if($file != "." && $file != "..") {
  8.         chmod($dir.$file, 0777);
  9.         if(is_dir($dir.$file)) {
  10.             chdir('.');
  11.             while($dir.$file) {
  12.                 if(date("U",filectime($file) >= time() - $old)
  13.                 {
  14.                     unlink($dir.$file)
  15.                 }
  16.             }
  17.  
  18.         }
  19.         else
  20.             unlink($dir.$file) or DIE("couldn't delete $dir$file<br />");
  21.     }
  22. }
  23. closedir($mydir);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement