php遍历路径——php经典实例
代码:
<html> <head> <title>遍历目录</title> <meta charset="utf-8" /> </head> <body> <h1>遍历目录</h1> <table border='1' cellpadding='10' cellspacing='0'> <tr> <th>文件名</th> <th>类型</th> <th>大小</th> <th>创建时间</th> </tr> <?php //定义要遍历的路径 $dir="/"; //打开路径返回句柄 $dd=opendir($dir); //遍历 while(false !== ($f=readdir($dd))){ echo "<tr>"; if($f=="." || $f==".."){ continue; } $file=rtrim($dir,"/")."/".$f; $f2=iconv("GB2312","UTF-8",$file); echo "<td>{$f2}</td>"; echo "<td>".filetype($file)."</td>"; echo "<td>".filesize($file)."</td>"; echo "<td>".date("Ymd h:i",filectime($file))."</td>"; echo "</tr>"; } //关闭句柄 closedir($dd); ?> </table> </body> </html>