-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.php
executable file
·212 lines (195 loc) · 7.16 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE HTML> <html lang="en"> <head>
<meta charset="UTF-8">
<link href="http://libs.baidu.com/bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet">
<script src="http://libs.baidu.com/bootstrap/2.3.2/js/bootstrap.min.js"></script>
<title>Offline Download</title>
<style type="text/css">
body{
font-family:Microsoft YaHei;
}
</style>
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a href="http://sysucs.org" class="brand">sysucs.org</a>
</div>
</div>
</div>
<br />
<br />
<br />
<div class="container">
<header>
<h1 onclick="reloadPage()">离线下载?</h1>
</header>
<div id="downloading" class="alert alert-info">
<p>欢迎使用!采用wget后台下载的方法实现简单的离线下载功能,wget更多使用方法请查看 <a href="http://www.gnu.org/software/wget/manual/wget.html"><strong>wget使用说明</strong></a></p>
<p><b>注意:</b>文件有效期为48小时,请及时下载,到期将会自动删除!</p>
</div>
<form onSubmit="return downloading()" method="post">
<h3><code style="font-size:18px;">sysu@sysucs.org ~ $ wget -b -nc --restrict-file-names=nocontrol -P ./download   </code>
</h3>
<input id="url" name="url" type="text" placeholder="请把文件的下载地址粘贴到这里,然后回车即可。" style="width:700px;" />
<button type="submit" class="btn">Enter</button>
</form>
<div>
<?php
writelist("download");
?>
</div>
</div>
<script type="text/javascript">
function info(){
alert ("还没写好!");
}
function reloadPage(){
window.location.reload();
}
function downloading(){
var UU =document.getElementById("url");
if(UU == " ")
{
alert("地址为空!");
return false;
}
else return true;
}
var xtime = new Array();
var num = document.getElementById("xnumber").innerHTML;
document.getElementById("xnumber").innerHTML = "";
function timeRemain(){
for(var i=1;i<=num;i++){
var temp = xtime[i];
var h = Math.floor( temp / 3600);
temp %= 3600;
var m = Math.floor( temp / 60);
if(m<10) m = '0' + m.toString();
else m = m.toString();
temp %= 60;
var s = temp;
if(s<10) s = '0' + s.toString();
else s = s.toString();
document.getElementById("x"+i.toString()).innerHTML = (h.toString()+':'+m+':'+s);
}
for(var i=1;i<=num;i++){
xtime[i]--;
}
setTimeout("timeRemain()",1000);
}
for(var j = 1;j<=num;j++){
xtime[j] = document.getElementById("x"+j.toString()).innerHTML;
}
//alert("good");
timeRemain();
</script>
<div >
<p style="text-align:center">
Copyright © <a href="http://gmy.asia">gmy</a> & <a href="http://gracece.net">grace</a> 2012 </p>
</div>
</body>
</html>
<?php
function secondToDate($second,$iid) {
echo '<swan id="x'.$iid.'">'.$second.'</swan>';
}
function sortFileByDate($dir)
{
if(is_dir($dir))
{
$scanArray=scandir($dir);
$finalArray = array();
for($i=0; $i<count($scanArray);$i++)
{
if($scanArray[$i]!="."&&$scanArray[$i]!="..")
{
$finalArray[$scanArray[$i]]=filectime($dir."/".$scanArray[$i]);
}
}
arsort($finalArray);
return($finalArray);
//返回数组,key为文件名,value为文件时间
}
else
echo "sorry,".$dir."is not a dir";
}
function writelist($Spath){
echo' <table class="table table-striped table-bordered">
<thead>
<tr>
<th style="text-align:center;">#</th>
<th>名称(按下载时间排序)</th>
<th style="width:80px;">文件大小</th>
<th style="width:90px;">下载时间</th>
<th style="width:80px;">有效时间</th>
<th style="width:45px;">操作</th>
</tr>
</thead>
<tbody> ';
date_default_timezone_set("Asia/Shanghai");
$sortedPath = sortFileByDate($Spath);
$index = 0;
while ($element =each($sortedPath))
{
$longPath = "./".$Spath."/".$element['key'];
$size =filesize($longPath)/1024/1024;
$size = number_format($size,2);
//两位小数
$filedownloadtime = $element['value'];
$effecttime =172800-( time()- $filedownloadtime) ;
//有效时间为两天 48*60*60 = 172800, 有效时间为0则删除
if ($effecttime <0)
unlink($longPath);
$downtime_fomat = date('m/d H:i',$filedownloadtime);
//格式化显示
$index++;
echo '<tr>
<td style="text-align:center;width:60px;">'.$index.'</td>
<td><a target="_blank" title="点击下载" href='.$longPath.'>'.$element['key']."</a></td>
<td>".$size."MB</td>
<td>".$downtime_fomat."</td>
<td>";
secondToDate($effecttime,$index);
echo "</td>
<td><input class='btn btn-danger' type='submit' value='delete' onclick='info()' style='padding:0 0 ;' /></td>
</tr>
";
}
echo "</table>";
echo "<p id='xnumber'>".$index."</p>";
}
function safePost($str)
{
$val = !empty($_POST["$str"]) ? $_POST[$str]:null;
return $val;
}
$url = safePost("url");
$name = safePost("filename");
$allow_type=array("wmv","apk","deb","iso","xls","xlsx","exe","cpp","pdf","gif","mp3","mp4","zip","rar","doc","docx","mov","ppt","pptx","txt","7z","jpeg","jpg","JPEG","png");
//允许的文件类型
$torrent = explode(".",$url);
$file_end = end($torrent);
$file_end = strtolower($file_end);
if(in_array($file_end,$allow_type))
{
shell_exec("wget -b -nc --restrict-file-names=nocontrol -P ./download ".escapeshellarg($url));
// -b 后台下载
// -nc 文件已经存在时不覆盖
// --restrict-file-names 解决中文地址导致文件名乱码的问题
// -P 保存路径
echo "<script type='text/javascript'>
reloadPage();
</script>";
}
else if($file_end != null)
{
echo '<div class="alert alert-danger"> 类型: '. $file_end . '<br />';
echo"<button class='close' data-dismiss='alert'>x</button>";
echo "这个文件类型不允许!";
echo "允许的文件有:</br>";
foreach($allow_type as $xxx)
echo $xxx . "、 ";
echo "</br> 如有需要,请与管理员联系!</div>";
}
?>