| 
 
 代码如下:  
<!DOCTYPE html>  <html>  ?? ?<head>  ?? ??? ?<title>php读取目录信息</title>  ?? ??? ?<meta charset="utf-8"/>  ?? ?</head>  ?? ?<body>  ?? ??? ?<center>  ?? ??? ??? ?<h2>文件目录</h2>  ?? ??? ??? ?<table border='1' width='1200' cellspacing='0' cellpadding='5'>  ?? ??? ??? ??? ?<tr>  ?? ??? ??? ??? ??? ?<th>编号</th>  ?? ??? ??? ??? ??? ?<th>文件名</th>  ?? ??? ??? ??? ??? ?<th>文件类型</th>  ?? ??? ??? ??? ??? ?<th>文件大小</th>  ?? ??? ??? ??? ??? ?<th>是否可读</th>  ?? ??? ??? ??? ??? ?<th>是否可写</th>  ?? ??? ??? ??? ??? ?  ?? ??? ??? ??? ??? ?<th>是否可执行</th>  ?? ??? ??? ??? ??? ?<th>创建时间</th>  ?? ??? ??? ??? ??? ?<th>修改时间</th>  ?? ??? ??? ??? ??? ?<th>访问时间</th>  ?? ??? ??? ??? ??? ?<th>操作</th>  ?? ??? ??? ??? ?</tr>  ?? ??? ?<?php  ?? ??? ??? ?echo "<pre>";  ?? ??? ??? ?//1.定义要读取的目录  ?? ??? ??? ?$path = "./";  ?? ??? ??? ?  ?? ??? ??? ?//2.打开目录  ?? ??? ??? ?$resource = opendir($path);  ?? ??? ??? ?$a=0;  ?? ??? ??? ?//3.读取内容  ?? ??? ??? ?while($file = readdir($resource)){  ?? ??? ??? ??? ?  ?? ??? ??? ??? ?//① 过滤 . 和 .. 特殊目录  ?? ??? ??? ??? ?if($file=='.' || $file=='..'){  ?? ??? ??? ??? ??? ?  ?? ??? ??? ??? ??? ?//② 跳过循环  ?? ??? ??? ??? ??? ?continue;  ?? ??? ??? ??? ?}  ?? ??? ??? ?  ?? ??? ??? ?  ?? ??? ??? ?//4.关闭目录  ?? ??? ??>  ?? ??? ??? ??? ?<tr>  ?? ??? ??? ??? ??? ?<td><?=$a++;?></td>  ?? ??? ??? ??? ??? ?<td><?=$file;?></td>  ?? ??? ??? ??? ??? ?<td><?=filetype($file);?></td>  ?? ??? ??? ??? ??? ?<td><?=round(filesize($file)/1024,2);?>Kb</td>  ?? ??? ??? ??? ??? ?<td><?=is_readable($file)==1?"是":"否";?></td>  ?? ??? ??? ??? ??? ?<td><?=is_writable($file)==1?"是":"否";;?></td>  ?? ??? ??? ??? ??? ?<td><?=is_executable($file)==1?"是":"否";;?></td>  ?? ??? ??? ??? ??? ?<td><?=date("Y-m-d H:i:s",filectime($file));?></td>  ?? ??? ??? ??? ??? ?<td><?=date("Y-m-d H:i:s",fileatime($file));?></td>  ?? ??? ??? ??? ??? ?<td><?=date("Y-m-d H:i:s",filemtime($file));?></td>  ?? ??? ??? ??? ??? ?<td>  ?? ??? ??? ??? ??? ??? ?<a href='./mulu.php?filename=<?= $file ?>'>删除</a>  ?? ??? ??? ??? ??? ??? ?  ?? ??? ??? ??? ??? ?</td>  ?? ??? ??? ??? ?</tr>  ?? ??? ?<?php  ?? ??? ??? ?}  ?? ??? ??? ??? ??? ??? ?//判断filename是否有名字  ?? ??? ??? ?if(!empty($_GET['filename']) && file_exists($path.$_GET['filename'])){  ?? ??? ??? ??? ?unlink($path.$_GET['filename']);  ?? ??? ??? ??? ?die("  ?? ??? ??? ??? ??? ?<script>  ?? ??? ??? ??? ??? ??? ?alert('恭喜,删除成功!');  ?? ??? ??? ??? ??? ??? ?window.location.href='./mulu.php';?? // 打开当前URL页面  ?? ??? ??? ??? ??? ?</script>  ?? ??? ??? ??? ??? ?");  ?? ??? ??? ?}  ?? ??? ??>  
?? ??? ?</script>  ?? ??? ??? ?</table>  ?? ??? ?</center>  ?? ?</body>  </html>  
运行结果:  
   
? 
                
        
        
    
 
 |