$newest = true;
$dir = '/usr/leyangjun/local/etc/nginx/servers/';
$dh = opendir($dir);
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($fileName = readdir($dh)) !== false){
if ($fileName != "." && $fileName != "..") {
$fileNamePath = $dir.$fileName;
$fileArr[$fileNamePath] = date("Y-m-d H:i:s",filemtime($fileNamePath));
}
}
arsort($fileArr);//倒序
if ($newest) {//取最新一条
$needKey = count($fileArr) - 1;
$fileArr[] = $fileArr[$needKey];
}
closedir($dh);
}
}
PHP 读取文件时间排序取值
最新推荐文章于 2023-12-14 16:44:04 发布
本文介绍了一个用于检测Nginx服务器目录下文件最新修改情况的脚本,通过遍历指定目录,获取所有非.和..的文件路径及最后修改时间,并按时间倒序排列,最终取出最新的文件记录。
1195

被折叠的 条评论
为什么被折叠?



