diff --git a/index.php b/index.php index 7109126..fa4b312 100644 --- a/index.php +++ b/index.php @@ -1,492 +1,444 @@ - '无法创建目录: ' . $upload_dir]); - exit; - } - } - - // 生成文件扩展名 - $file_extension = strtolower(pathinfo($name, PATHINFO_EXTENSION)); - - // 生成随机文件名 - $randomFileName = generateRandomFileName() . '.' . $file_extension; - - // 使用相对路径获取目标文件 - $target_file = $upload_dir . '/' . $randomFileName; - - // 检查上传错误 - if ($error !== UPLOAD_ERR_OK) { - switch ($error) { - case UPLOAD_ERR_INI_SIZE: - case UPLOAD_ERR_FORM_SIZE: - echo json_encode(['error' => '文件过大,最大允许上传:' . $max_upload_size]); - exit; - - case UPLOAD_ERR_PARTIAL: - echo json_encode(['error' => '文件部分上传失败']); - exit; - - case UPLOAD_ERR_NO_FILE: - echo json_encode(['error' => '没有文件被上传']); - exit; - - case UPLOAD_ERR_CANT_WRITE: - echo json_encode(['error' => '写入失败,无法保存文件']); - exit; - - case UPLOAD_ERR_EXTENSION: - echo json_encode(['error' => '文件上传被扩展程序阻止']); - exit; - - default: - echo json_encode(['error' => '上传失败,错误代码:' . $error]); - exit; - } - } - - // 检查硬盘空间 - if (disk_free_space($upload_dir) < filesize($file_tmp)) { - echo json_encode(['error' => '硬盘空间不足,请清理磁盘后再进行操作']); - exit; - } - - // 移动文件 - if (move_uploaded_file($file_tmp, $target_file)) { - $domain = $_SERVER['HTTP_HOST']; - $relative_path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $upload_dir); - $download_url = "http://$domain" . rtrim($relative_path, '/') . '/' . rawurlencode($randomFileName); - echo json_encode(['upload_url' => htmlspecialchars($download_url)]); - } else { - echo json_encode(['error' => '写入失败,无法保存文件']); - } - exit; -} -?> - - - - - - - - 一个简单的图床 - - - -
-
-
-

一个简单的图床

-
-
- - -
- -
-
-
- -
支持格式: JPEG, PNG, GIF, WEBP, AVIF, BMP, SVG
-
-
-
- - - - \ No newline at end of file + + + + + + + + + 一个简单的图床 + + + +
+
+
+

一个简单的图床

+
+
+ + +
+ +
+
+
+ +
支持格式: JPEG, PNG, GIF, WEBP, AVIF, BMP, SVG 最大上传:
+
+
+
+ + + +