<?php
header("Content-Type:text/html;charset=utf-8");
$path='./';
if(isset($_GET['dir'])){
$path=$_GET['dir'];
if(realpath($path)==realpath(dirname(__FILE__))) $path='.';
if(is_file($path)){
echo '<pre>';
echo htmlspecialchars(file_get_contents($path));
echo '</pre>';
exit;
}
}
list_addlink($path);
/**
+--------------------------------------------
*列出路径下所有文件或文件夹,并附加链接
+--------------------------------------------
public
+--------------------------------------------
string $path 文件夹或文件的路径
*/
function list_addlink($path){
if(file_exists($path)){
if(is_file($path)){
echo "文件:<a href=\"".$_SERVER['PHP_SELF']."?dir={$path}\">{$path}</a><br/>";
}else if(is_dir($path)){
$dir=opendir($path);
while($files=readdir($dir)){
if(is_file($files)){
echo "文件:<a href=\"".$_SERVER['PHP_SELF']."?dir={$path}/{$files}\" target=\"_blank\">{$files}</a><br/>";
}else if(is_dir($path.'/'.$files)){
if(realpath($path)==realpath('..')) die('参数错误');
if(realpath($path)==dirname(__FILE__)){
//echo '<hr/>'.$files.'<hr/>';
if($files!='.' && $files!='..'){
echo "目录:<a href=\"".$_SERVER['PHP_SELF']."?dir={$path}/{$files}\">{$files}</a><br/>";
}
}else{
if($files=='.' || $files=='..'){
echo "目录:<a href=\"".$_SERVER['PHP_SELF']."?dir={$path}/{$files}\">{$files}</a><br/>";
}else{
echo "目录:<a href=\"".$_SERVER['PHP_SELF']."?dir={$path}/{$files}\">{$files}</a><br/>";
}
}
}
}
closedir($dir);
}
}else{
die("文件或目录不存在");
}
}
?>