Re: Unlink file older then 7 days

From: Date: Wed, 18 Jul 2007 06:29:53 +0000
Subject: Re: Unlink file older then 7 days
References: 1 2 3 4 5 6 7 8  Groups: php.general 
Request: Send a blank email to php-general+get-259086@lists.php.net to get a copy of this message
Ok thanks everyone... I need to throw in a wildcard, how would I do that.. I have this so far. which dont work. <? $filename = '/home/public_html/client/test/*.txt.asc'; $filename2 = '/home/public_html/client/test/*.txt'; if (file_exists($filename) && filemtime($filename) < time()-(7*24*60*60)) { unlink($filename); unlink($filename2); } ?> Thankyou ----- Original Message ----- From: "Richard Lynch" <ceo@l-i-e.com> To: "Stut" <stuttle@gmail.com> Cc: "Suhas Pharkute" <psuhas@gmail.com>; <chris@aquanuke.com>; <php-general@lists.php.net> Sent: Wednesday, July 18, 2007 2:17 AM Subject: Re: [PHP] Unlink file older then 7 days
On Mon, July 16, 2007 8:40 am, Stut wrote:
Suhas Pharkute wrote:
http://us.php.net/manual/en/function.fileatime.php $filename = 'somefile.txt'; if (file_exists($filename) && fileatime($filename) < (time()-(7*24*60*60)) ) { unlink($filename); } Read docs!
You too! The OP wanted a way to "check the age of all files". The fileatime function will return when the file was last accessed. Accessing a file is not usually deemed to affect its age, modifying it is. The filemtime function is what the OP wants.
Unless he wants filectime, for when the file was created, even if it's been modified in the past week... "older" could mean that, in some contexts... I think finding all the .txt.asc files would best be handled by http://php.net/glob unless your PHP version is too old and you need to http://php.net/opendir and http://php.net/readdir to look at each file in turn... -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#259086) next »