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

相关文章

讲解WordPress开发中一些常用的debug技巧

讲解WordPress开发中一些常用的debug技巧

在开发过程中,调试代码是非常重要的工作,而掌握一些 WordPress 的调试技巧,可以更好的进行调试。比如,在本地开发环境,你可能需要把全部的代码警告信息全部输出出来,方便修改代码不合...

PHP使用Redis替代文件存储Session的方法

PHP使用Redis替代文件存储Session的方法

本文实例讲述了PHP使用Redis替代文件存储Session的方法。分享给大家供大家参考,具体如下: PHP默认使用文件存储session,如果并发量大,效率非常低。而Redis对高并发...

PHP开发中常用的8个小技巧

PHP批最取得checkbox的值 1、命名 <input type='checkbox' name='checkbox[]' value=$dwmyrow[banzhu] /&g...

PHP中phar包的使用教程

前言 PHP5.3之后支持了类似Java的jar包,名为phar。用来将多个PHP文件打包为一个文件。 首先需要修改php.ini配置将phar的readonly关闭,默认是不能写pha...

php中判断文件存在是用file_exists还是is_file的整理

看了这篇PHP中file_exists与is_file,is_dir的区别的说法基本明白,PHP的 file_exists = is_dir + is_file。 写程序验证一下: 分别...