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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.