Created
August 22, 2018 09:23
-
-
Save WaximeA/c1b756c14406d01c06fc9189642e0de0 to your computer and use it in GitHub Desktop.
Sort folders by their modification date instead of alphabetic order.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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