<?php
$path='./';
if(isset($_GET['dir'])){
$path=$path.$_GET['dir'];
}
$dh=opendir($path);
if($dh===false){
echo '打开出错';
exit;
}
while(($item = readdir($dh))!==false){
$list[]=$item;
}
print_r($list);
closedir($dh);
print_r($_SERVER);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h2>文件管理系统</h2>
<table>
<tr>
<td>序号</td>
<td>文件名</td>
<td>操作</td>
</tr>
<?php foreach ($list as $key => $value) { ?>
<tr>
<td><?php echo $key ?></td>
<td><?php echo $value ?></td>
<td><?php
if(is_dir($path.$value) && ($value=='.')) {
echo '<a href="new1.php?dir=',$value,'/">浏览</a>';
}elseif(is_dir($path.$value)) {
echo '<a href="new1.php?dir=',$value,'">浏览</a>';
}elseif(!(is_dir($path.$value))){
echo '<a href="./',$value,'">查看</a>';
}
?></td>
</tr>
<?php } ?>
</table>
</body>
</html>