<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> 遍历目录信息 </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content="dz5362"> <meta name="Keywords" content="dz5362"> <meta name="Description" content="no-description"> <meta http-equiv="Content-type" content="text/html;charset=GB2312"> <link rel='stylesheet' type='text/css' href='style.css'> </head> <body> <div id='header'>遍历指定目录信息</div> <div id='content'> <form method="post" action="cyg.php" id='myForm'> <center>请输入目录路径</center> <input type='text' name='path' size='25'><br> <input type="submit" value='查看' class='input'> </form> </div> <div id='footer'>cyg 2012</div> </body> </html> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <style> table{ border-collapse:collapse; border:1px solid #ccc; } table td{ border:1px solid #ccc; line-height:22px; background:#eee; } </style> </head> <body> <?php if($_POST['path']){ $path_start = $_POST['path']; //获取绝对路径 $path = opendir($path_start); //打开目录 ?> <center>目录信息如下表所示</center> <table border='0' cellspacing='0' cellpadding='0' width='450' align='center'> <tr align="left" bgcolor="#cccccc"> <th>文件名</th><th>大小</th><th>类型</th><th>修改时间</th> </tr> <?php $str = ''; while($file=readdir($path)){//读取某个目录下的信息 $dir = $path_start."/".$file; //获取完整的路径和文件名称 $str .= '<tr align=\'center\'>'; $str .= '<td>'.$file.'</td>'; $str .= '<td>'.ceil((filesize($dir))/1024).'kb</td>';//获取目录下某个文件的大小 $str .= '<td>'.(filetype($dir)=='dir'?'文件夹':'文件').'</td>';//看类型是文件还是文件夹 $str .= '<td>'.date("Y/n/t",filemtime($dir)).'</td>';//查看目录的日期 $str .= '</tr>'; } echo $str; ?> </table> <?php } ?> </body> </html>