Last active
March 28, 2023 15:05
-
-
Save joeydenbraven/bbeba738ee9981f289907a8d2821ae64 to your computer and use it in GitHub Desktop.
Scan dir sorted on modified date
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
function scan_dir($dir) { | |
$ignored = array('.', '..', '.svn', '.htaccess'); // -- ignore these file names | |
$files = array(); //----------------------------------- create an empty files array to play with | |
foreach (scandir($dir) as $file) { | |
if ($file[0] === '.') continue; //----------------- ignores all files starting with '.' | |
if (in_array($file, $ignored)) continue; //-------- ignores all files given in $ignored | |
$files[$file] = filemtime($dir . '/' . $file); //-- add to files list | |
} | |
arsort($files); //------------------------------------- sort file values (creation timestamps) | |
$files = array_keys($files); //------------------------ get all files after sorting | |
return ($files) ? $files : false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment