Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

display images in order created

images php coding issues or problems here.

Moderators: macek, egami, gesf

display images in order created

Postby kylehamilton » Sun Aug 01, 2010 12:56 pm

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>';
  }
 }
}


?>
kylehamilton
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sun Aug 01, 2010 12:46 pm

Re: display images in order created

Postby hema » Wed Aug 04, 2010 12:31 am

Hi,

U can display images in sort order by created date

Find this url http://webxadmin.free.fr/article/php-di ... te-209.php

I hope this may helpful to you.

Regards,
Mahe
hema
New php-forum User
New php-forum User
 
Posts: 13
Joined: Fri Jul 30, 2010 12:09 am

Re: display images in order created

Postby kylehamilton » Wed Aug 04, 2010 4:28 am

Thanks.
kylehamilton
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sun Aug 01, 2010 12:46 pm


Return to PHP coding => Images

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.