遍历指定目录下的所有目录和文件的php代码

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?php
function listFiles($path){
$result = array();
foreach(glob($path.'\\'."*") as $item){
$result[strtolower($item)] = $item;
if(is_dir($item)){
$result += listFiles($item);
}
}
return $result;
}
$path = 'E:\\web\\dianle';
foreach(listFiles($path) as $item){
echo $item.'<br />';
}

2: scandir 读取指定目录到数组
复制代码 代码如下:

function listFiles($path){
$result = array();
foreach( scandir($path) as $item ){
if($item != '.' && $item != '..' ){
$item = $path.'\\'.$item;
$result[strtolower($item)] = $item;
if(is_dir($item)){
$result += listFiles($item);
}
}
}
return $result;
}
$path = 'E:\\web\\dianle';
foreach(listFiles($path) as $item){
echo $item.'<br />';
}

相关文章

PHP中防止SQL注入攻击和XSS攻击的两个简单方法

mysql_real_escape_string() 所以得SQL语句如果有类似这样的写法:"select * from cdr where src =".$userId; 都要改成 $...

用C/C++扩展你的PHP 为你的php增加功能

用C/C++扩展你的PHP 为你的php增加功能

英文版下载: PHP 5 Power Programming https://www.jb51.net/books/61020.html PHP取得成功的一个主要原因之一是她拥有大量的可...

php读取30天之内的根据算法排序的代码

复制代码 代码如下:<?php $link=mysql_connect("","","") or die("无法连接到mysql数据库".mysql_error());...

解决nginx不支持thinkphp中pathinfo的问题

解决nginx不支持thinkphp中pathinfo的问题

下面小编通过文字加代码的方式给大家详解下,具体内容如下: 其实,要解决nginx不支持pathinfo的问题,有两个解决思路,一是不使用pathinfo模式,二是修改nginx的配置文件...

Apache 配置详解(最好的APACHE配置教程)

Apache的配置 Apache的配置由httpd.conf文件配置,因此下面的配置指令都是在httpd.conf文件中修改。 主站点的配置(基本配置) (1) 基本配置: Serv...