Skip to content

Instantly share code, notes, and snippets.

@joeydenbraven
Last active March 28, 2023 15:05
Show Gist options
  • Save joeydenbraven/bbeba738ee9981f289907a8d2821ae64 to your computer and use it in GitHub Desktop.
Save joeydenbraven/bbeba738ee9981f289907a8d2821ae64 to your computer and use it in GitHub Desktop.
Scan dir sorted on modified date
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