On Tue, May 24, 2005 7:24 am, Rahul S. Johari said:
> Iım trying to delete all files in a folder based on a string match with
> the
> following code:
>
> <?
> $dir = '/Library/WebServer/Documents/something.com/subfolder/';
> $dp = opendir($dir) or die ('Fatal Error: '.mysql_error());
> while ($file = readdir($dp)) {
> if ((eregi('.png',$file)) && (filemtime($dir.$file)) <
> (strtotime('yesterday'))) {
> unlink($dir.$file);
> }
> }
> closedir($dp);
> $yesterday = mktime( 0, 0, 0, date("m") , date("d")-1, date("Y") );
> $date = date( "m-d-y, D", $yesterday );
> echo "<B>Erase Successful!</B><br>All images up to $date, have been
> permanently erased from the Server.";
> ?>
>
> I need the code to delete all images created till yesterday, and leave
> images created today. Somehow strtotime(Œyesterdayı) doesnıt work.
> If I put strtotime(Œ-2 daysı) or strtotime(Œ-7 daysı) or even
> strtotime(Œ8:00amı)... They all work accordingly. How come (Œyesterdayı)
> isnıt working? It doesnıt delete anything.

Maybe strtotime('-1 day') would work. [shrug]

You could also use http://php.net/mktime

mktime(date('m'), -1); //This should be 24 hours before 'now', I think...

Or maybe mktime(date('m'), date('d) -1);

Whichever it is, PHP's mktime does the right thing even if you use, like:
mktime(6, 0); //This is really May 31st, not June 0. PHP knows.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to