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;
    }
?>

相关文章

PHP similar_text 字符串的相似性比较函数

PHP 提供了一个极少使用的 similar_text 函数,但此函数非常有用,用于比较两个字符串并返回相似程度的百分比,以下是similar_text () 函数的使用方法: 复制代码...

PHP单例模式模拟Java Bean实现方法示例

PHP单例模式模拟Java Bean实现方法示例

本文实例讲述了PHP单例模式模拟Java Bean实现方法。分享给大家供大家参考,具体如下: 问题: 根据如下杨辉三角形 实现一个get_value($row,$col)方法: (前一...

Windows下编译PHP5.4和xdebug全记录

实际上我最终目的是编译得到支持 PHP5.4 的 php_xdebug.dll,而在此之前,成功编译 PHP5.4 是必须的。 编译环境以及相关软件包: 1.Microsoft Visu...

php 如何获取文件的后缀名

比如图片文件的后缀,jpg或gif等 有两个方法 一,假如$img为图片文件名 $img=12345.gif; $img_ext = substr($img, strrpos($im...

FirePHP 推荐一款PHP调试工具

FirePHP 推荐一款PHP调试工具

PHP调试有很多中方法。今天给大家推荐的是 FirePHP(http://www.firephp.org/)。 这个工具,是基于firefox的一个组件。Firephp组件安装地址。使用...