This repository has been archived by the owner on Jul 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
65 lines (63 loc) · 1.87 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
54
55
56
57
58
59
60
61
62
63
64
65
<?php
include "internal.php";
// Set header
header('Content-type: application/json');
// Check permission
if (!checkPermission("upload")) {
exit(errorJson("Permission denied"));
}
// Process argument
$id = $_REQUEST["id"];
if ($id == null) {
exit(errorJson("Missing argument 'id'"));
}
// Get backup
$backup = getBackup($id);
if ($backup == null || !$backup->isUploading) {
exit(errorJson("Backup '$id' is not found!"));
}
// Process file
$file = $_FILES["file"];
if ($file == null) {
exit(errorJson("Missing argument 'file'"));
}
if (getMaxSize() > 0 && $backup->size + $file["size"] > getMaxSize()) {
exit(errorJson("Backup size limit exceeded! Max backup size: " . getMaxSize() . " MB"));
}
$fn = $file["name"];
foreach (getBannedFiles() as $bfn) {
if (fnmatchReal($bfn, $fn)) {
exit(errorJson("File name '$fn' is banned"));
}
}
$dir = $_REQUEST["dir"];
if ($file["error"] == 0) {
if (getMaxFileSize() > 0 && $file["size"] > getMaxFileSize()) {
exit(errorJson("File size limit exceeded! Max file size: " . getMaxFileSize() . " MB"));
}
$tmp = $file["tmp_name"];
$target = getBackupPath() . $id . "/" . $fn;
move_uploaded_file($tmp, $target);
$backup->size += $file["size"];
++$backup->uploadedFiles;
if ($backup->totalFiles == 0) {
exit(json_encode([
"success" => true,
"id" => $id,
"uploadedFiles" => $backup->uploadedFiles
]));
}
if ($backup->totalFiles == $backup->uploadedFiles) {
$backup->isUploading = false;
$backup->save();
}
exit(json_encode([
"success" => true,
"id" => $id,
"uploadedFiles" => $backup->uploadedFiles,
"totalFiles" => $backup->totalFiles,
"done" => $backup->totalFiles == $backup->uploadedFiles
]));
} else {
exit(errorJson("Failed to upload. Error code: " . $file["error"]));
}