Jump to content

script to remove files of certain age from server


timdiacon

Recommended Posts

Hello,

I am using fpdf to create PDF's store them on my server and then allow people to download them. However I would like to add a line in my pdf generation script which searches the directory where they are stored and removes any PDF's that are more than a week old.

Any help on how to do this would be much appreciated.

Thanks.
actually I think I have found the answer on php.net...

[code]
if (is_dir("$path") )
       {
           $handle=opendir($path);
           while (false!==($file = readdir($handle))) {
               if ($file != "." && $file != "..") {  
                   $Diff = (time() - filectime("$path/$file"))/60/60/24;
                   if ($Diff > 14) unlink("$path/$file");

               }
           }
           closedir($handle);
       }
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.