<?php
/*使用opendir()
readdir()
closedir()
rewinddir()
进行目录的遍历
*/
$sum = 0;
$dirname = 'D:\PHP\wamp64\www\demo';
$dir_handle = opendir($dirname);
echo '<table border="0" aline="center" width="600" cellspacing="0" cellpadding="0">';
echo '<caption><h2>目录'.$dirname.'下面的文件</h2></caption>';
echo '<tr align="left" bgcolor="#8fbc9f">';
echo '<th>文件名</th><th>文件大小</th><th>文件类型</th><th>修改时间</th></tr>';
while($file = readdir($dir_handle)){
//把目录下的文件名和当前目录的路径链接起来,如此在程序中才能使用。
$dirfiel = $dirname."/".$file;
$bgcolor = $sum++%2==0 ? '#FFFFFF' : '#deb887';
echo '<tr bgcolor='.$bgcolor.'>';
echo '<td>'.$file.'</td>';
echo '<td>'.filesize($dirfiel).'</td>';
echo '<td>'.filetype($dirfiel).'</td>';
echo '<td>'.date("Y/n/d",filemtime($dirfiel)).'</td>';
echo '</tr>';
}
echo '</table>';
closedir($dir_handle);
echo '文件共有'.$sum.'个';
?>
遍历目录
最新推荐文章于 2024-02-27 18:59:56 发布