第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > php 遍历文件夹下的所有文件名以及文件大小

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

时间:2022-01-09 09:47:16

相关推荐

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);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。