I am using the code below to echo out all the files from a directory onto a page. The order of the files that are echoed out are in a random order, i.e,
File 3
File 1
File 2
Instead of
File 1
File 2
File 3
How do I make it so that the files that are echoed out are based on when it was created or uploaded. The most recent files will appear at the top of the list, and the oldest file will appear at the bottom
if ($handle = opendir('.')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." && !in_array($entry, $blacklist)) {
echo "<p>$entry\n</p>";
}
}
closedir($handle);
}