Not entirely beautiful, but may allow additional features:
<?php
$dir = 'lib';
$files = scandir($dir);
$files = array_diff($files, array('.', '..'));
foreach ($files as $file) {
$path = $dir . '/' . $file;
if (is_file($path) && file_exists($path) && is_readable($path)) {
$sorted[] = array(
'ctime'=>filectime($path),
'mtime'=>filemtime($path),
'atime'=>fileatime($path),
'filename'=>$path,
'filesize'=>filesize($path)
);
}
}
asort($sorted);
print_r(array_values($sorted));
?>
Conclusion:
Array
(
[0] => Array
(
[ctime] => 1289415301
[mtime] => 1289415301
[atime] => 1299182410
[filename] => lib/example_lib3.php
[filesize] => 36104
)
[1] => Array
(
[ctime] => 1297202755
[mtime] => 1297202722
[atime] => 1297202721
[filename] => lib/example_lib1.php
[filesize] => 16721
)
[2] => Array
(
[ctime] => 1297365112
[mtime] => 1297365112
[atime] => 1297365109
[filename] => lib/example_lib2.php
[filesize] => 57778
)
)
source
share