-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathapi.php
More file actions
50 lines (41 loc) · 1.43 KB
/
Copy pathapi.php
File metadata and controls
50 lines (41 loc) · 1.43 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
50
<?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)) {
jsonExit(['status' => false, 'message' => '无文件上传', 'data' => []]);
}
$uploadCheck = isUploadAllowed(
$pdo,
getConfigInt($pdo, 'max_uploads_per_day'),
resolveUploadUserId($pdo),
getClientIp()
);
if ($uploadCheck !== true) {
jsonExit(['status' => false, 'message' => $uploadCheck, 'data' => []]);
}
$maxFileSize = getConfigInt($pdo, 'max_file_size');
foreach ($_FILES as $file) {
if ($file['size'] > $maxFileSize) {
jsonExit(['status' => false, 'message' => '文件大小超过限制,最大允许 ' . ($maxFileSize / (1024 * 1024)) . 'MB', 'data' => []]);
}
}
validateUploadAccess($pdo);
foreach ($_FILES as $file) {
handleUploadedFile($file);
}
} catch (Exception $e) {
logMessage('错误: ' . $e->getMessage());
jsonExit(['status' => false, 'message' => '请求失败,请稍后重试', 'data' => []]);
}