php遍历指定目录下指定类型的文件

来源:赵克立博客 分类: PHP 标签:遍历PHP发布时间:2018-11-09 16:32:47最后更新:2019-03-02 16:49:40浏览:996
版权声明:
本文为博主原创文章,转载请声明原文链接...谢谢。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;
}



微信号:kelicom QQ群:215861553 紧急求助须知
Win32/PHP/JS/Android/Python