I’m using this to return images in the order they were added to the directory, however I want them to be ordered from newest to older. How can I do it? Thanks
<?
$handle = @opendir("images");
if(!empty($handle)) {
while(false !== ($file = readdir($handle))) {
if(is_file("images/" . $file))
echo '<img src="images/' . $file . '"><br><br>';
}
}
closedir($handle);
?>
If you want them ordered from newest to older, then you cannot rely on just readdir. That order might be arbitrary. You’ll need to sort them by timestamps: