首页 > 开发 > PHP > 正文

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

2024-05-04 22:13:04
字体:
来源:转载
供稿:网友
读取目录下所有文件的代码,可以不管文件名
代码如下:
<?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);  
   }  
}  
?> 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表