Jump to content


Photo

script to remove files of certain age from server


  • Please log in to reply
2 replies to this topic

#1 timdiacon

timdiacon
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 March 2006 - 12:40 PM

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.

#2 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 08 March 2006 - 12:43 PM

Wow, I'd like to know the answer to that as well!

That being said, could you trying incorporating the date into the file name?

Or, perhaps you could track PDF creation with a table? Then you could use the table to tell you which one to delete?


#3 timdiacon

timdiacon
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 March 2006 - 12:46 PM

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

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); 
       }





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users