PHP遍历目录的代码
时间:2021-07-01 10:21:17
帮助过:18人阅读
PHP目录的遍历 - //php目录的遍历
- function showDetail($dirname){
- $ds = opendir($dirname);
- while($file = readdir($ds)){
- $path = $dirname."/".$file;
- if($file != "." && $file != ".."){ //这里是个坑
- if(is_dir($path)){
- showDetail($path); //递归调用,如果读出的是目录则继续读取
- }else{
- echo $path."
"; - }
- }
- }
- }
- $dirname="test"; //测试一个目录
- showDetail($dirname);
- ?>
|
PHP