ディレクトリ内の最も古いファイル、すべての中で最も古いファイル (特定のフォルダのディレクトリ、サブディレクトリを含む) を見つける必要があります。
Folder 1
- dir 1
- dir 1.1
- file 1
- dir 2
- dir 2.1
- file 2
ファイル 2 が最も古い場合、メイン ディレクトリ名 (フォルダ 1) を渡して最も古いファイル (ファイル 2) を取得できるようにする必要があります。
私の解決策は
function get_oldest_file($dir) {
$filemdate = array();
print $dir.PHP_EOL;
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
$files[] = $file;
print $file.PHP_EOL;
}
foreach ($files as $eachfile) {
if (is_file($dir.eachfile)) {
$file_date[$eachfile] = filemtime($dir.$eachfile);
print $filemdate[$eachfile].PHP_EOL;
}
}
}
closedir($handle);
asort($filemdate, SORT_NUMERIC);
reset($filmdate);
$oldest = key($filemdate);
print "Oldest is : ".$oldest;
return $oldest;
}
echo get_oldest_file("/path/---")
ありがとう !