newest images, how to find

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
modplod
Forum Commoner
Posts: 45
Joined: Mon Feb 27, 2006 11:18 am

newest images, how to find

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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);
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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.
modplod
Forum Commoner
Posts: 45
Joined: Mon Feb 27, 2006 11:18 am

Post 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.
modplod
Forum Commoner
Posts: 45
Joined: Mon Feb 27, 2006 11:18 am

Post by modplod »

Fayd, is the comma in the list statment ment to be there? (never seen that before)

Code: Select all

list(,$files)...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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? :)
modplod
Forum Commoner
Posts: 45
Joined: Mon Feb 27, 2006 11:18 am

Post by modplod »

err, I guess :lol:
modplod
Forum Commoner
Posts: 45
Joined: Mon Feb 27, 2006 11:18 am

Post 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?
Post Reply