-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathapi.php
More file actions
49 lines (40 loc) · 1.24 KB
/
Copy pathapi.php
File metadata and controls
49 lines (40 loc) · 1.24 KB
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
<?php
ob_start();
session_start();
require_once __DIR__ . '/includes/bootstrap.php';
require_once __DIR__ . '/includes/http.php';
require_once __DIR__ . '/includes/storage.php';
require_once __DIR__ . '/includes/image.php';
$pdo = Database::getInstance()->getConnection();
try {
setCorsHeaders();
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
ob_end_clean();
http_response_code(204);
exit;
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || empty($_FILES)) {
uploadFailExit('无文件上传');
}
$uploadCheck = isUploadAllowed(
$pdo,
getConfigInt($pdo, 'max_uploads_per_day'),
resolveUploadUserId($pdo),
getClientIp()
);
if ($uploadCheck !== true) {
uploadFailExit($uploadCheck);
}
$maxFileSize = getConfigInt($pdo, 'max_file_size');
foreach ($_FILES as $file) {
if ($file['size'] > $maxFileSize) {
uploadFailExit('文件大小超过限制,最大允许 ' . ($maxFileSize / (1024 * 1024)) . 'MB');
}
}
validateUploadAccess($pdo);
foreach ($_FILES as $file) {
handleUploadedFile($file);
}
} catch (Exception $e) {
uploadFailExit('请求失败,请稍后重试', 200, $e->getMessage());
}