最後に変更したときとは逆の順序で画像を表示しようとしています。残念ながら、get_headers()はURLに対してのみ機能するようで、stat ['mtime']とfilemtime()の両方が失敗します。ファイルの最終変更情報を取得する他の方法はありますか?現時点での私のコードは次のとおりです。
if (isset($_GET['start']) && "true" === $_GET['start'])
{
$images = array();
if ($dir = dir('images'))
{
$count = 0;
while(false !== ($file = $dir->read()))
{
if (!is_dir($file) && $file !== '.' && $file !== '..' && (substr($file, -3) === 'jpg' || substr($file, -3) === 'png' || substr($file, -3) === 'gif'))
{
$lastModified = filemtime($file);
$images[$lastModified] = $file;
++$count;
}
}
echo json_encode($images);
}
else { echo "Could not open directory"; }
}