PHP遍历某个目录下的所有文件和子文件夹的实现代码

yipeiwu_com6年前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内嵌函数用法。分享给大家供大家参考。具体分析如下: php中可以在函数内部内嵌一个函数,调用范围仅限于函数本身 <?php function msg...

php正则提取html图片(img)src地址与任意属性的方法

简单版: <?php header("Content-Type: text/html;charset=utf-8"); $str = '<div class="...

关于初学PHP时的知识积累总结

PHP基础一、初识PHPPHP是与HTML混合使用的嵌入式语言。1、PHP标记默认标记<?php ?> 短标记<? ?>,需在php.ini中将short_ope...

set_include_path在win和linux下的区别

刚刚调式程序,本来在服务器上好好的程序到了win下居然出错。 后来仔细调式才发现是set_include_path的问题。 在win下,当你要include多个路径的...

php生成酷炫的四个字符验证码

本文实例为大家分享php生成验证码的实现代码,供大家参考,具体内容如下 <?php $im=imagecreate(200,100);//生成画布 imagecolo...