note 108773 deleted from function.filemtime by danbrown

From: Date: Wed, 23 May 2012 22:56:15 +0000
Subject: note 108773 deleted from function.filemtime by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-188180@lists.php.net to get a copy of this message
Note Submitter: no at email dot com ---- Hi, I have a php code that reads all jpg files from a (thumbnail-)folder and then displays thumbnails on a web page sorted by the date picture was added to the folder. But now I'd like to create index page that would display only 2-3 files from a folder. Can someone please help how to edit the code so that it will display only 2 or 3 most recent jpg's in folder? My current php code is the following: <? $names = array(); //$dates = array(); $dir = 'galerii/loodus/loojang';//direction of thumbnails. php reads and sorts images by date of thumbnails. if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if (strlen($file) - strpos(strtoupper($file), '.JPG') == 4) { $names[] = $file; $dates[] = filectime("$dir/$file"); } } closedir($handle); } arsort($dates); foreach ($dates as $key=>$value) { $file = $names[$key]; $str = $file; //file name without extension $str = explode(".", $str); //file name without extension $failinimi_laiendita = $str[0]; //file name without extension - needed for displaying large pictures in another folder where large pictures have an addition in file name. //$date = date('d-m-Y', $value); echo " <a class='thumb_name' href='$dir/suured/$failinimi_laiendita","_suur.jpg' rel='lightbox[roadtrip]' title='Faili nimi: $failinimi_laiendita'> <div id='galerii_foto' align='center'> <img src='$dir/$file' border='1' style='border-color:#999999; vertical-align:top;' align='center'/><table border='0' cellspacing='0' cellpadding='0'><tr><td valign='bottom'>$failinimi_laiendita</td></tr></table> </div> </a> "; } ?> I believe the loop or for i section should be added near echo sentences but unfortunately I have no idea how to add it and how does the current codes displays jpg's. I mean does it starts from the oldest or newest.

« previous php.notes (#188180) next »