display images by date created

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
kyleiwaniec
Forum Newbie
Posts: 14
Joined: Tue Jun 22, 2010 2:21 pm

display images by date created

Post by kyleiwaniec »

I have the following code which displays images and captions from a directory. I would like the images to be displayed in the order they were created. Somebody suggested I use glob(), but I have no idea how.

Code: Select all

<?php
$dir = "exclusive_images/";
if ($opendir = opendir($dir)) {
 //read directory

 while(($file = readdir($opendir)) !==FALSE) {
if ( file_exists($dir.'/'.$file) && in_array( strtolower(pathinfo($file,PATHINFO_EXTENSION )), array('png','jpg','jpeg','gif'))) {
   if (file_exists($dir.'/'.$file. '.txt')) 
   $caption = file_get_contents($dir.'/'.$file. '.txt');
   else    $caption = ucwords(str_replace(array('-','_'),' ', substr($file, 0, (strlen ($file)) - (strlen (strrchr($file,'.'))))));
   echo '<tr><td><img src="' . $dir.'/'.$file .'" alt="'. $file .'" title="' . $file . '" width="200"></td><td>' . $caption . '</td></tr>';
  }
 }
}


?>
d8p
Forum Newbie
Posts: 4
Joined: Mon Aug 02, 2010 5:38 am

Re: display images by date created

Post by d8p »

This thread might help you but I'm not sure it's possible to get the proper creation date.

Hope this helps.
User avatar
Grizzzzzzzzzz
Forum Contributor
Posts: 125
Joined: Wed Sep 02, 2009 8:51 am

Re: display images by date created

Post by Grizzzzzzzzzz »

kyleiwaniec wrote:I have the following code which displays images and captions from a directory. I would like the images to be displayed in the order they were created. Somebody suggested I use glob(), but I have no idea how.
try this
Post Reply