使用php scandir()函数遍历文件夹并输出所有文件路径
以F盘为例:
1 <?php
2
3
4 $dir = "F:"; //当前目录
5
6
7 function list_file($dir){
8 $list = scandir($dir); // 得到该文件下的所有文件和文件夹
9 foreach($list as $file){//遍历
10 $file_location=$dir."/".$file;//生成路径
11 if(is_dir($file_location) && $file!="." &&$file!=".."){ //判断是不是文件夹
12 echo $file_location.'<br />';
13 list_file($file_location); //继续遍历
14 }
15 }
16 }
17
18
19 list_file($dir);
20
21
22 ?>
执行以上代码可以得到你电脑上F盘的所有文件夹路径!