当前位置:首页 > PHP教程 > PHP常见问题

PHP读取目录下所有文件的代码

读取目录下所有文件的代码,可以不管文件名
复制代码 代码如下:

<?php  
$dir = "file";  

// open a known directory, and proceed to read its contents  
if (is_dir($dir)) {  
   if ($dh = opendir($dir)) {  

       while (($file = readdir($dh)) !== false) {  
       if ($file!="." && $file!="..") {  
       echo "<a href=file/".$file.">".$file."</a><br>";  
       }  
       }  
       closedir($dh);  
   }  
}  
?> 

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!