-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.php
163 lines (140 loc) · 4.4 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/**
* 对文件 路径进行编码
*
* @param string $path
*/
function encodePath($path)
{
$tmp_array = explode('/', $path);
foreach ($tmp_array as $key => $value){
if ($value == '') //删除空内容
unset($tmp_array[$key]);
$tmp_array[$key]=rawurlencode($value);
}
return implode("/", $tmp_array);
}
/**
* 显示验证的输入窗口
* @param string $user 用户名
* @param string $pass 密码
* @access public
*/
function webAuthenticate($user,$pass){
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !isset($user) || !isset($pass)
|| $_SERVER['PHP_AUTH_USER']!=$user | $_SERVER['PHP_AUTH_PW']!=$pass
)
{
header('WWW-Authenticate: Basic realm="Authentication System"');
header('HTTP/1.0 401 Unauthorized');
echo "You must enter a valid login ID and password to access this resource ";
exit;
}
return true;
}
if(!webAuthenticate("ggg","123")) //验证用户
{
die();
}
//2005-4-11
//显示当前目录下的文件
$_CONFIG["SiteName"]="文件下载系统 by ggg "; //网站名称
$_CONFIG["SiteUrl"]="http://soft.zggo.com"; //网站地址
?>
<!DOCTYPE html>
<html>
<head>
<title><?php print($_CONFIG["SiteName"])." ".$_CONFIG["SiteUrl"];?></title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<center><font color=#ee0000><?php print($_CONFIG["SiteName"]);?></font>
<br><a href=<?php print($_CONFIG["SiteUrl"]);?>><?php print($_CONFIG["SiteUrl"]);?></a></center>
<table border=1 width=98% align="center" bordercolordark="#FFFFFF" cellpadding="2" cellspacing="2">
<tr>
<?php
$_DIR_PATH="./";
echo strpos($_GET["dir"],"..");
//die();
if(!empty($_GET["dir"]) && strlen($_GET["dir"])>3 && ".."!=substr($_GET["dir"], 0, 2) && !(strpos($_GET["dir"],"..")>=0))
{
$prevRealpath=dirname($_GET["dir"]); //得到上一层的目录
if(substr($_GET["dir"], -1) != '/')
{ $_GET["dir"] .= '/';
}
$_DIR_PATH=$_GET["dir"];
print($_DIR_PATH);
//die();
print("<td>当前目录路径:[<b>".$_DIR_PATH."</b>]</td>");
print("<td align=right>");
print(" <a href='?dir='>");
print("[返回根目录]");
print("</a>");
print(" <a href='?dir=".rawurlencode($prevRealpath)."'>");
print("返回上一层目录");
print("</a> ");
print("</td>");
}
$numb=0;
if(empty($_DIR_PATH))
$DIRObject=dir("./");
else
$DIRObject=dir($_DIR_PATH);
?>
</tr></table>
<table border=1 width=98% align="center" bordercolordark="#FFFFFF" cellpadding="2" cellspacing="2">
<?php
while($tmp_Str=$DIRObject->read())
{
if($tmp_Str!="."&&$tmp_Str!="..")
{
$numb++;
print("<tr>");
if(is_dir($DIRObject->path.$tmp_Str)) //是目录
{
print("<td align=center>");
print(strftime("%Y-%m-%d %H:%M:%S",filemtime($_DIR_PATH.$tmp_Str)));
print(" </td>");
print("<td>");
print("<a href='?dir=".encodePath($_DIR_PATH.$tmp_Str)."'>");
print("[<font color=red>目录</font>] ");
print("</a>");
print(" </td>");
print("<td>");
print("<a href='?dir=".encodePath($_DIR_PATH.$tmp_Str)."'>");
print($tmp_Str);
print("</a>");
print(" </td>");
}
else //其他显示的文件
{
if(strstr($tmp_Str,".php") || strstr($tmp_Str,".asp") ) //不显示 .php .asp的文件
continue;
print("<td align=center>");
print(strftime("%Y-%m-%d %H:%M:%S",filemtime($_DIR_PATH.$tmp_Str)));
print(" </td>");
print("<td>");
print(filesize($_DIR_PATH.$tmp_Str)."");
$kbSize=round(filesize($_DIR_PATH.$tmp_Str)/1000,2);
$mbSize=round($kbSize/1000,2);
if($mbSize>1)
print("[".$mbSize."MB]");
else
print("[".$kbSize."KB]");
print(" </td>");
print("<td>");
print("<a target=_blank href='".encodePath($_DIR_PATH.$tmp_Str)."'>");
print($tmp_Str); //$_DIR_PATH.
print("</a>");
print(" </td>");
}
print("</tr>");
//if($numb%5==0)
// print("</tr><tr>");
}
}
$DIRObject->close();
?>
</table>
</body>
</html>