Unlink - file deletion

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Unlink - file deletion

Post by snicolas »

Hi,

I am creating some fynamic pdf in the root folder.
I have a script that i can run manually to delete all ".pdf" files.
I would like this script to run automatically when creating the pdf. and delete the files (pdf) older than 1 hour....
How can i do this?

Code: Select all

<?php

foreach (glob("*.pdf") as $filename) {
   echo "$filename size " . filesize($filename) . "\n";
   unlink($filename);
}

?>
thanks

s
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

Code: Select all

if ((time() - 3600) > filemtime($filename)) &#123;
    unlink($filename);
&#125;
snicolas
Forum Commoner
Posts: 97
Joined: Tue Nov 09, 2004 8:32 am

Post by snicolas »

Thanks rehfeld, worked perfectly....

I was testing the creation of pdf and automatic deletion..now this works...
My ultimate goal is to be able to post information from a form and insert these information into a template pdf...
I had a look at fpdi, but it's not really clear...
Does anybody have a proper example, with a form?

Thanks again for the help.

s
Post Reply