Ashley M. Kirchner wrote:
I have files that are named in the following manner:
file..jpg (where is an hhmm timestamp [hour and minutes])
What's the best way to take the current hhmm timestamp and run
backwards finding the previous 5 files, and checking whether
sorry, clicked on send too fast ;)
i'd extract the minues and seconds , generate an array of timestamps and
sort that array desc
--
View this message in context:
http://www.nabble.com/Checking-file-existence-tf2636778.html#a7359891
Sent from the PHP - General mailing list archive at
one solution could probably be made using: glob(), sort() and/or filemtime().
btw: I assume your aware that the filenames are not very unique (i.e. twice a
day, everyday a given file will potentially be overwritten) and that this
is intentional
Ashley M. Kirchner wrote:
I have files that
Edward Kay wrote:
Are all the files called file..jpg or could they have other names such
as clouds.1123.jpg, field.2034.jpg etc?
They are all the same exact file name with the only difference being
the timestamp.
Alternatively, you could get the OS to do the work through an exec call
UntestedCode
$img_array = array();
$i = 0;
while(count($img_array) 5) {
$hhmm = date(Hi, strtotime(-$i minutes));
$filename = file.$hhmm.jpg;
if(file_exists(/path/to/$filename)) {
$img_array[] = $filename;
}
$i++;
}
[mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 15, 2006 10:56 AM
To: php-general@lists.php.net
Subject: RE: [PHP] Checking file existence
UntestedCode
$img_array = array();
$i = 0;
while(count($img_array) 5) {
$hhmm = date(Hi, strtotime(-$i minutes));
$filename = file
Hi Ashley,
Are all the files called file..jpg or could they have other names such
as clouds.1123.jpg, field.2034.jpg etc?
If they all have the same name, you could use something like scandir() and
then just use the first 5 items in the returned array.
You could also loop through the
Surely it would be simpler to store all this info in a database table? e.g.
id : int
created : timestamp
filename : varchar
Only files that actually existed would be in the DB, plus you could do all
your sorting on the 'created' timestamp column. Querying the DB should be
much simpler
[mailto:[EMAIL PROTECTED]
Sent: Wednesday, November 15, 2006 10:56 AM
To: php-general@lists.php.net
Subject: RE: [PHP] Checking file existence
UntestedCode
$img_array = array();
$i = 0;
while(count($img_array) 5) {
$hhmm = date(Hi, strtotime(-$i minutes));
$filename
Stut wrote:
mall, minor, insignificant point If I have less than 5 files this
loop will never end. But you all knew that right?
Yup. I break out of the loop if $i reaches 10 for some weird reason.
Also, depending on the frequency of files (i.e. are there months-worth
of gaps or
At 8:18 AM -0700 11/15/06, Ashley M. Kirchner wrote:
I have files that are named in the following manner:
file..jpg (where is an hhmm timestamp [hour and minutes])
What's the best way to take the current hhmm timestamp and run
backwards finding the previous 5 files, and
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
12 matches
Mail list logo