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实现针对日期,月数,天数,周数,小时,分,秒等的加减运算示例【基于strtotime】

本文实例讲述了PHP实现针对日期,月数,天数,周数,小时,分,秒等的加减运算方法。分享给大家供大家参考,具体如下: 其实就是strtotime这个内置函数 //PHP 日期 加减 周...

php一些公用函数的集合

/*获得客户端ip地址*/     function getIP() {      &...

php列出一个目录下的所有文件的代码

复制代码 代码如下: <?php function dir_path($path) { $path = str_replace('\\', '/', $path); if (sub...

curl 出现错误的调试方法(必看)

实例如下: private function httpGet($url) { $curl = curl_init(); curl_setopt($curl,...

修改Laravel5.3中的路由文件与路径

前言 大家可能没有注意到, 在 Laravel 4 以及更老版本中, 路由逻辑是性能上的一个瓶颈--特别是对于有很多路由定义的应用而言. 一个只有几百条路由定义的 Laravel 站点...