php遍历某个目录下的文件
PHP代码
<?php $num=0; //用来记录目录下的文件个数
$dirname='LAMP'; //要遍历的目录名字
$dir_handle=opendir($dirname);
echo '<table border="1" align="center" width="960px" cellspacing="0" cellpadding="0">';
echo '<caption><h2>目录'.$dirname.'下面的内容</h2></caption>';
echo '<tr>';
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>';
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 '';
closedir($dir_handle);
echo '在<b>'.$dirname.'</b>目录下的子目录和文件共有<b>'.$num.'</b>个';
?>
php免费学习视频:立即使用
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!










