Re: Checking file existence
| From: | Stut | Date: | Wed, 15 Nov 2006 16:52:44 +0000 |
| Subject: | Re: Checking file existence | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-244683@lists.php.net to get a copy of this message | ||
John Pillion wrote:
Very nifty Brad, One addition though, so she/you can work back from any point: <MoreUntestedCode> $i = 0; $start = strtotime("2006-10-05 12:05am"); while(count($img_array) < 5) { $year = date("Y", strtotime("-$i minutes", $start)); $month= date("m", strtotime("-$i minutes", $start)); $day = date("d", strtotime("-$i minutes", $start)); $hour = date("H", strtotime("-$i minutes", $start)); $hhmm = date("Hi", strtotime("-$i minutes", $start)); $filename = "file.$hhmm.jpg"; if(file_exists("/path/to/$year/$month/$day/$hour/$filename")) { $img_array[] = $filename; } $i++; } print_r($img_array); </MoreUntestedCode>Small, minor, insignificant point.... If I have less than 5 files this loop will never end. But you all knew that right? Also, depending on the frequency of files (i.e. are there months-worth of gaps or minutes at most), the following might be faster... * glob the files in the first dir * binary chop to find the nearest to your start time * go back in the array from that point to find your 5 * if you hit the start of the array, go down a day, repeat the glob and start from the end of the new array -Stut