遍历指定目录下的所有目录和文件的php代码
遍历指定目录下的所有目录和文件的php代码
发布时间:2016-12-29 来源:查字典编辑
摘要:复制代码代码如下:

复制代码 代码如下:

<?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:webdianle';

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:webdianle';

foreach(listFiles($path) as $item){

echo $item.'<br />';

}

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新php教程学习
热门php教程学习
编程开发子分类