php遍历指定目录下指定类型的文件
版权声明:
本文为博主原创文章,转载请声明原文链接...谢谢。o_0。
更新时间:
2019-03-02 16:49:40
温馨提示:
学无止境,技术类文章有它的时效性,请留意文章更新时间,如发现内容有误请留言指出,防止别人"踩坑",我会及时更新文章
/**
* 返回当前目录下所有的php文件,不带全路径
* @param [type] $dir 如 e:/dir/dir
* @return [type] [description]
*/
function getDirAllFile($dir, $fileType = '.png')
{
$list = [];
if (!file_exists($dir)) {
return [];
}
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if ($file != '.' && $file != '..' && strtolower(substr($file, -4)) == strtolower($fileType)) {
$list[] = $file;
}
}
closedir($dh);
}
ksort($list, SORT_STRING | SORT_NATURAL | SORT_FLAG_CASE);
return $list;
}