22 lines
940 B
PHP
22 lines
940 B
PHP
![]() |
<?php include('container/security.php'); ?>
|
||
|
<?php
|
||
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||
|
// File upload handling
|
||
|
if (isset($_FILES['file']) && $_FILES['file']['error'] == 0) {
|
||
|
$file_tmp = $_FILES['file']['tmp_name'];
|
||
|
// 使用当前时间生成文件名
|
||
|
$file_path = "assets/images/uploads/" . date('YmdHis') . '-' . uniqid() . '.jpg'; // 假设文件格式为jpg
|
||
|
|
||
|
if (move_uploaded_file($file_tmp, $file_path)) {
|
||
|
// 上传成功返回文件链接
|
||
|
echo json_encode(['success' => true, 'filePath' => $file_path]);
|
||
|
} else {
|
||
|
echo json_encode(['success' => false, 'message' => 'Error moving uploaded file.']);
|
||
|
}
|
||
|
} else {
|
||
|
echo json_encode(['success' => false, 'message' => 'No file uploaded or upload error.']);
|
||
|
}
|
||
|
} else {
|
||
|
echo json_encode(['success' => false, 'message' => 'Invalid request method.']);
|
||
|
}
|
||
|
?>
|