龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

PHP遍历某个目录下的文件

时间:2014-07-22 14:50来源: 作者: 点击:
分享到:
<无详细内容>
<?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 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);
   echo '在<b>'.$dirname.'</b>目录下的子目录和文件共有<b>'.$num.'</b>个';
?>
精彩图集

赞助商链接