<?php
error_reporting(0);
$basedir = "c:/filelist";
if(!is_dir($basedir)) $basedir = dirname(__FILE__);
$file_name = $_GET['downfile'];
if(!empty($file_name)){
$file_dir = $basedir . "/" . $file_name;
if(dirname(realpath($file_dir)) < $basedir){
echo "Permission Denied!";
exit;
}
if (!file_exists($file_dir)) {
echo "File Not Found!";
exit;
} else {
$file = fopen($file_dir,"r");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($file_dir));
Header("Content-Disposition: attachment; filename=" . $file_name);
echo fread($file,filesize($file_dir));
fclose($file);
exit;
}
}
header("Content-type: text/html; charset=utf-8");
$requestDir = $_GET['dir'];
if(empty($requestDir)){
$dir = $basedir;
}else{
$dir = $basedir . "/" . $requestDir;
}
$dir = realpath($dir);
if($dir < $basedir) $dir = $basedir;
?>
<html>
<head>
<title>File Listing</title>
<STYLE type="text/css">
body {
font-family: "Courier New", "Verdana", "Tahoma";
font-size: 12px;
}
td {
font-family: "Courier New", "Verdana", "Tahoma";
font-size: 12px;
}
input {
font-family: "Courier New", "Verdana", "Tahoma";
font-size: 12px;
}
.title {
font-family: "Verdana", "Tahoma";
font-size: 22px;
font-weight: bold;
}
</STYLE>
</head>
<body>
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td class="title">File Listing</td>
<td align="right" valign="bottom"><font color="#FF0000"><h2><a href="logout.php">Sign Out</a></h2>
</font>
</td>
</tr>
</table>
<hr width="100%" style="border:1px dashed black; height:1px">
<table width="100%" border="0" cellpadding="3" cellspacing="1">
<tr>
<td><?php
$predir = realpath($dir . "/../");
if($predir > $basedir) $predir = str_replace($basedir . "/","",$predir);
if($predir == $basedir) $predir = ".";
if($dir > $basedir) echo "<a href=\"?dir=". $predir ."\">Up Level</a>";
?>
</td>
</tr>
<?php
$dirs=@opendir($dir);
$count = 0;
while($file=@readdir($dirs)) {
$b="$dir/$file";
$a=@is_dir($b);
if($a=="1"){
if($file!=".."&&$file!=".") {
if($count < 1){
$count ++;
echo "<tr>\n";
echo "<td><b>Folder</b></td>\n";
echo "</tr>\n";
}
echo "<tr>\n";
echo "<td><a href=\"?dir=" . ($dir > $basedir ? str_replace($basedir . "/",'',$dir . "/") : '') . urlencode($file)."\">$file</a></td>\n";
echo "</tr>\n";
}
}
}
@closedir($dirs);
?>
</table>
<hr width="100%" style="border:1px dashed black; height:1px">
<table width="100%" border="0" cellpadding="3" cellspacing="1">
<tr>
<td><b>Filename</b></td>
<td><b>Date</b></td>
<td><b>Size</b></td>
<td><b>Action</b></td>
</tr>
<?php
$dirs=@opendir($dir);
while ($file=@readdir($dirs)) {
$b="$dir/$file";
$a=@is_dir($b);
if($a=="0"){
$size=@filesize("$dir/$file");
$size=$size/1024 ;
$size= @number_format($size,2);
$lastsave=@date("Y-n-d H:i:s",filemtime("$dir/$file"));
echo "<tr>\n";
echo "<td>$file</td>\n";
echo "<td>$lastsave</td>\n";
echo "<td>$size KB</td>\n";
echo "<td><a href=\"?downfile=".($dir > $basedir ? str_replace($basedir . "/",'',$dir . "/") : '').urlencode($file)."\">Download</a></td>\n";
echo "</tr>\n";
}
}
@closedir($dirs);
?>
</table>
<hr width="100%" style="border:1px dashed black; height:1px">
<?php include View::getView('side'); include View::getView('footer');?>
1 个解决方案
#1
太长了,指出关键代码?
#1
太长了,指出关键代码?