-
Notifications
You must be signed in to change notification settings - Fork 2
/
upload.php
53 lines (42 loc) · 1.06 KB
/
upload.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
<?php
session_start();
include("settings.php");
if (!isset($_SESSION["auth"])) {
echo "<meta http-equiv='refresh' content='0;URL=admin.php'>";
exit;
}
$path = "contents/upload/";
if ($_POST["mode"] == "upload") {
$dest = $path . $_FILES['file']['name'];
$t = 0;
while(file_exists($dest)) {
$dest = $path . $_FILES['file']['name'];
$dest = substr($dest, 0, strpos($dest, ".")) . "_$t" . strstr($dest, ".");
$t++;
}
move_uploaded_file($_FILES['file']['tmp_name'], $dest);
}
if ($_GET["mode"] == "delete" && !empty($_GET["file"])) {
unlink($_GET["file"]);
}
$template = new AdminTemplate;
$list = array();
$dh = opendir($path);
if ($dh != false) {
while (($file = readdir($dh)) !== false) {
if ($file == "." || $file == "..") {
continue;
}
$list[] = array(filemtime($path . $file), $file);
}
}
closedir($dh);
rsort($list);
$files = array();
foreach($list as $f) {
$files[] = array("path" => $path . $f[1], "name" => $f[1]);
}
$template->assign("files", $files);
$template->display("upload.tpl");
# vim: ts=8 sw=2 sts=2 noet
?>