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的面向对象引擎提供了一个非常聪明的特性,就是,可以使用foreach()方法通过循环方式取出一个...

邮箱正则表达式实现代码(针对php)

一直都在网上抄别人写的电话,邮箱正则表达式,今天稍微有点闲情,把一直想自己写个这样的表达式的心愿给完成:复制代码 代码如下:/** * 邮箱地址正则表达式 */$pr...

php使用CutyCapt实现网页截图保存的方法

本文实例讲述了php使用CutyCapt实现网页截图保存的方法。分享给大家供大家参考,具体如下: 网页截图这个功能大家可能用到最多的就是QQ截图,或利用asp.net来实现截图,其实我们...

PHP中spl_autoload_register函数的用法总结

spl_autoload_register(PHP 5 >= 5.1.2)spl_autoload_register — 注册__autoload()函数 说明bool spl_a...

asp.net和php的区别点总结

asp.net和php哪个更好? 在.net之前,微软的是ASP。在微软的大力推广下,其看起来还是很有前途的。但现在,微软想推广asp.net,而ASP成了其障碍。所以从Windows...