I'm creating an image gallery and would like for my most recent uploaded images to be at the front.
This is what I currently have:
$files = glob("images/*.*");
for ($i=0; $i<count($files); $i++) {
$image = $files[$i];
$supported_file = array('gif','jpg','jpeg','png');
$ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
if (in_array($ext, $supported_file)) {
echo basename($image)."<br />"; // show only image name if you want to show full path then use this code // echo $image."<br />";
echo '<img src="'.$image .'" alt="Random image" />'."<br /><br />";
} else {
continue;
}
}
But I'm not sure how to make it display in order of last uploaded.