Home > php教程 > php手册 > php遍历目录输出目录及其下的所有文件示例

php遍历目录输出目录及其下的所有文件示例

WBOY
Release: 2016-06-06 20:25:15
Original
1271 people have browsed it

好多次笔试都会遇到这个问题,本文特写下php遍历目录输出目录及其下的所有文件的方法

好多次笔试都会遇到这个问题,,所以特意给写了出来

复制代码 代码如下:


function my_scandir($dir){
$files=array();
if(is_dir($dir)){
if($handle=opendir($dir)){
while(($file=readdir($handle))!==false){
if($file!='.' && $file!=".."){
if(is_dir($dir."/".$file)){
$files[$file]=my_scandir($dir."/".$file);
}else{
$files[]=$dir."/".$file;
}
}
}
}
}
closedir($handle);
return $files;
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template