Skip to content

Instantly share code, notes, and snippets.

@joeydenbraven
joeydenbraven / scan_dir.php
Last active March 28, 2023 15:05
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