Skip to content

Instantly share code, notes, and snippets.

@otkrsk
Created July 20, 2016 08:59
Show Gist options
  • Save otkrsk/59d7b24f04d977883f4bb70b540ce3ce to your computer and use it in GitHub Desktop.
Save otkrsk/59d7b24f04d977883f4bb70b540ce3ce to your computer and use it in GitHub Desktop.
Scan a directory and sort the files according to the last modified date.
<?php
function scan_dir($dir) {
$ignored = array('.', '..', '.svn', '.htaccess');
$files = array();
foreach (scandir($dir) as $file) {
if (in_array($file, $ignored)) continue;
$files[$file] = filemtime($dir . '/' . $file);
}
arsort($files);
$files = array_keys($files);
return ($files) ? $files : false;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment