我是靠谱客的博主 开心夕阳,这篇文章主要介绍PHP遍历某个目录下的所有文件和子文件夹的实现代码,现在分享给大家,希望可以做个参考。

复制代码 代码如下:

<?php
 function read_all_dir ( $dir )
    {
        $result = array();
        $handle = opendir($dir);
        if ( $handle )
        {
            while ( ( $file = readdir ( $handle ) ) !== false )
            {
                if ( $file != '.' && $file != '..')
                {
                    $cur_path = $dir . DIRECTORY_SEPARATOR . $file;
                    if ( is_dir ( $cur_path ) )
                    {
                        $result['dir'][$cur_path] = read_all_dir ( $cur_path );
                    }
                    else
                    {
                        $result['file'][] = $cur_path;
                    }
                }
            }
            closedir($handle);
        }
        return $result;
    }
?>

最后

以上就是开心夕阳最近收集整理的关于PHP遍历某个目录下的所有文件和子文件夹的实现代码的全部内容,更多相关PHP遍历某个目录下内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(157)

评论列表共有 0 条评论

立即
投稿
返回
顶部