i have a question, can php get newest file in directory without scan all file? because i have a lot of folder with a hundred files, and it take so long to get newest file here's my code
$dir = new DirectoryIterator($d);
foreach ($dir as $f) {
if ($f->isFile()) {
$files[$f->getMTime()] = $d.$f->getFilename();
}
}
and i have another alternative
if ($handle = opendir($d)) {
while (false !== ($f = readdir($handle))) {
$f = $d.$f;
if(is_file($f)) {
$files[filemtime($f)] = $f;
}
}
closedir($handle);
}