Page 1 of 1

newest images, how to find

Posted: Thu Mar 09, 2006 12:14 pm
by modplod
Hi all, I'm looking for a hint on how to display the three newest images within a set of galleries.

The code should be able to search a dir structure and out put an array of three images like below

Code: Select all

$newImages = Array ($pathToImage, image_date)
I'm just starting this task so any hints would be a great help
Thanks

Posted: Thu Mar 09, 2006 12:24 pm
by feyd
take the function I posted here to get a list of files in the galleries. You'll then have to look at each file retrieving their filemtime() to create a sortable list like this:

Code: Select all

list(,$files) = directoryTraverse('galleries', true);

$files = array_flip($files);
foreach($files as $file => $v)
{
  $files[$file] = filemtime($file);
}
rsort($files)
$newest = array_slice($files, 0, 3);

Posted: Thu Mar 09, 2006 12:25 pm
by hawleyjr
Store the image info in a table. If you don't you will have to scan each image for its last modified date. Which, if you have a bunch of time can take some time.

Posted: Thu Mar 09, 2006 12:34 pm
by modplod
first thanks feyd for the code, will try soon, but can it search all the subdirectories, and is there a way to make it exclued some folders? (_thumbs)

next,
hawleyjr wrote:Store the image info in a table. If you don't you will have to scan each image for its last modified date. Which, if you have a bunch of time can take some time.
I understand that i will have run the function every time a user calles the page, could I store the list in $_GET? or would it be better to use a session, i realy dont want to use SQL or any other DB if possible, this site has to be very portable and easy to admin.

Posted: Thu Mar 09, 2006 1:04 pm
by modplod
Fayd, is the comma in the list statment ment to be there? (never seen that before)

Code: Select all

list(,$files)...

Posted: Thu Mar 09, 2006 1:50 pm
by feyd
modplod wrote:Fayd, is the comma in the list statment ment to be there? (never seen that before)

Code: Select all

[feyd@home]>php -r "list(,$foo) = array('foo','bar');echo $foo;"
bar
answer the question? :)

Posted: Thu Mar 09, 2006 1:56 pm
by modplod
err, I guess :lol:

Posted: Thu Mar 09, 2006 2:07 pm
by modplod
i just thourht of a better flow for my script...

if I was to look at the directories instead of the files first to derive wich has had files added, then just search the files within thoes folders, for the newest files
kind of like

->find the 3 newest (or last updated) folders
-->look within newest folders for newest files
--->place filepath/name string in array

would this speed things along?
would I be able to find the correct files?
or would it just create problems?