Skip to content

Instantly share code, notes, and snippets.

@a1phanumeric
Created December 14, 2012 09:39
Show Gist options
  • Select an option

  • Save a1phanumeric/4284074 to your computer and use it in GitHub Desktop.

Select an option

Save a1phanumeric/4284074 to your computer and use it in GitHub Desktop.

Revisions

  1. a1phanumeric created this gist Dec 14, 2012.
    20 changes: 20 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    <?php
    // Removes files older than a day

    $dir = '/path/to/dir';

    if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {

    $filelastmodified = filemtime($dir . '/' . $file);
    $filetype = filetype($dir . '/' . $file);

    if($filetype != 'file') continue;

    if((time() - $filelastmodified) > 24*3600){
    unlink($dir . '/' . $file);
    }
    }
    closedir($handle);
    }
    ?>