php 遍历文件夹下的所有文件名以及文件大小

 

$num=0;    //用来记录目录下的文件个数
$dirname='files/faces'; //要遍历的目录名字
$dir_handle=opendir($dirname);

echo '<table border="1" align="center" width="960px" cellspacing="0" cellpadding="0">';
echo '<caption><h2>目录'.$dirname.'下面的内容</h2></caption>';
echo '<tr align="left" bgcolor="#cccccc">';
echo '<th>文件名</th><th>文件大小</th><th>文件类型</th><th>修改时间</th></tr>';
while($file=readdir($dir_handle))
{
if($file!="."&&$file!="..")
{
$dirFile=$dirname."/".$file;
if($num++%2==0) //隔行换色
$bgcolor="#ffffff";
else
$bgcolor="#cccccc";
echo '<tr bgcolor='.$bgcolor.'>';
echo '<td>'.$file.'</td>';
echo '<td>'.filesize($dirFile).'</td>';
echo '<td>'.filetype($dirFile).'</td>';
echo '<td>'.date("Y/n/t",filemtime($dirFile)).'</td>';
echo '</tr>';
}
}
echo '</table>';
closedir($dir_handle);
posted @ 2016-05-30 09:27  秋风落叶.  阅读(917)  评论(0编辑  收藏  举报