// Grab all files from the desired folder
$files = glob('./test/*.*');
// Sort files by modified time, latest to earliest
// Use SORT_ASC in place of SORT_DESC for earliest to latest
array_multisort(
array_map('filemtime', $files),
SORT_NUMERIC,
SORT_ASC,
$files
);
echo $files[0] // the latest modified file should be the first.
는 this 웹 사이트
행운
편집에서 촬영 :
$files = glob('./test/*.*');
$exclude_files = array('.', '..');
if (!in_array($files, $exclude_files)) {
// Sort files by modified time, latest to earliest
// Use SORT_ASC in place of SORT_DESC for earliest to latest
array_multisort(
array_map('filemtime', $files),
SORT_NUMERIC,
SORT_ASC,
$files
);
}
echo $files[0];
당신이 보는 무엇을 알고있는 경우에 도움이됩니다 : 불필요한 검색을 줄이기 위해 디렉토리에있는 파일을 제외하려면 당신이 배제 할 수있는 것.
나는 당신의 대답을 좋아하지 만, 그 많은 파일들로 인해 PHP는 메모리가 다 소모되어 끝나기 전에 스크립트가 죽습니다. – BLAKE
폴더, 텍스트 파일, 스크립트를 확인하지 않을 특정 파일을 필터링 할 수 있습니까? $ exclude_files = array ('.', '..') –
아니요, 모든 파일의 이름은 % timestamp-guid % .tmp입니다. ''이외의 파일은 제외 할 수 없습니다. 및 '..'. – BLAKE