note 108773 added to function.filemtime
| From: | no at email dot com | Date: | Wed, 23 May 2012 22:27:35 +0000 |
| Subject: | note 108773 added to function.filemtime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188179@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 94.76.225.145
Probable Submitter: 62.65.196.113
----
Manual Page -- http://www.php.net/manual/en/function.filemtime.php
Edit -- https://master.php.net/note/edit/108773
Del: integrated -- https://master.php.net/note/delete/108773/integrated
Del: useless -- https://master.php.net/note/delete/108773/useless
Del: bad code -- https://master.php.net/note/delete/108773/bad+code
Del: spam -- https://master.php.net/note/delete/108773/spam
Del: non-english -- https://master.php.net/note/delete/108773/non-english
Del: in docs -- https://master.php.net/note/delete/108773/in+docs
Del: other reasons-- https://master.php.net/note/delete/108773
Reject -- https://master.php.net/note/reject/108773
Search -- https://master.php.net/manage/user-notes.php