Reputation: 25
Im using this code to list all the images in a folder on the page, the class "results" holds the 4 images per paginated page. I can only get them to list in alphabetical order, how can I get them by most recently added?
<?php
$files = glob("upload_image/*.*");
for ($i = 0; $i < count($files); $i += 4) {
$colCnt++;
if ($colCnt == 1) {
$num = $files[$i];
}
echo '<div class="result"><img src="' . $files[$i] .
'" /><img src="' . $files[$i + 1] .
'" /><img src="' . $files[$i + 2] .
'" /><img src="' . $files[$i + 3].'" /> ';
echo'</div>';
if ($colCnt == 1) {
$colCnt = 0;
}
}
?>
Upvotes: 0
Views: 74
Reputation: 46900
Using filemtime over the results will get you all their times and then you can simply sort that array based upon that time.
<?php
$files = glob("upload_image/*.*");
usort($files, create_function('$a,$b', 'return filemtime($a) - filemtime($b);'));
?>
Upvotes: 2