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

yipeiwu_com5年前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;
    }
?>

相关文章

Zend Studio (eclipse)使用速度优化方法

原文标题是优化 myeclipse7.0 速度(尤其是building workspace),都是eclipse设置一样的。 大家一定对buileding workspace时那缓慢的速...

PHP加密解密类实例分析

本文实例讲述了PHP加密解密类。分享给大家供大家参考。具体分析如下: 这段代码支持 数组加密 , 密文有效期, 各种对称加密 其中参数如下: * @use ption::en($stri...

fleaphp crud操作之find函数的使用方法

find函数的原型 复制代码 代码如下: /** * 返回符合条件的第一条记录及所有关联的数据,查询没有结果返回 false * * @param mixed $conditions *...

PHP实现无限级分类(不使用递归)

PHP实现无限级分类(不使用递归)

无限级分类在开发中经常使用,例如:部门结构、文章分类。无限级分类的难点在于“输出”和“查询”,例如 将文章分类输出为<ul>列表形式; 查找分类A下面所有分类包含的...

PHP数据类型的总结分析

PHP共有8中数据类型: 类型名称 类型表示 取值 bool 布尔型 true,false integer 整型 -2147483647-2147483648 string...