Skip to content

Instantly share code, notes, and snippets.

@WaximeA
Created August 22, 2018 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WaximeA/c1b756c14406d01c06fc9189642e0de0 to your computer and use it in GitHub Desktop.
Save WaximeA/c1b756c14406d01c06fc9189642e0de0 to your computer and use it in GitHub Desktop.
Sort folders by their modification date instead of alphabetic order.
<?php
$folder = "files/";
$handle = opendir($folder);
# Making an array containing the files in the current directory:
while ($file = readdir($handle)){
if( $file != ".." && $file != "." ){
$key = filemtime($file);
$files[$key] = $file ;
}
}
closedir($handle);
// sort files by mtime:
ksort($files) ;
#echo the files
foreach ($files as $file) {
echo "<a href=$folder$file target='read'>$file</a>"."<br />" ;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment