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实现的随机IP函数【国内IP段】

本文实例讲述了PHP实现的随机IP函数。分享给大家供大家参考,具体如下: function get_rand_ip(){ $arr_1 = array("218","218","...

php 获取SWF动画截图示例代码

1.下载附件,并安装,方法看附件中的帮助 2.拷贝代码进合适位置,生成图片,怎么处理,自己看着办喽 复制代码 代码如下: $oldswf = "/uploads/swf/test.swf...

Apache下禁止php文件被直接访问的解决方案

Apache下禁止php文件被直接访问的解决方案

  一开始,我想在重写规则里直接禁止php后缀的URL被访问。但后来发现重写规则是递归调用的,如果在重写规则里直接禁止php,那么重写到php文件的规则也会失效。RewriteEngin...

Asp.net 文本框全选的实现

一、鼠标滑过textbox全选 前台: <asp:TextBox runat="server" onMouseOver="this.focus();this.select()"&g...

有关PHP性能优化的介绍

PHP优化对于PHP的优化主要是对php.ini中的相关主要参数进行合理调整和设置,以下我们就来看看php.ini中的一些对性能影响较大的参数应该如何设置。 # vi /etc/php....