This commit is contained in:
icret
2024-01-19 22:21:12 +08:00
parent a1e80599dd
commit fe237dd712
58 changed files with 1944 additions and 2355 deletions

View File

@@ -1,5 +1,6 @@
<?php
namespace Verot\Upload;
require_once __DIR__ . '/../app/function.php';
@@ -19,10 +20,11 @@ header("Content-type: application/json; charset=utf-8");
if (empty($_FILES['image'])) {
exit(json_encode(
array(
"result" => "failed",
"code" => 204,
"message" => "没有选择上传的文件",
)
"result" => "failed",
"code" => 204,
"message" => "没有选择上传的文件",
),
JSON_UNESCAPED_UNICODE
));
}
@@ -31,24 +33,31 @@ if ($config['check_ip']) {
if (checkIP(null, $config['check_ip_list'], $config['check_ip_model'])) {
// 上传错误 code:205 未授权IP
exit(json_encode(array(
"result" => "failed",
"code" => 205,
"message" => "黑名单内或白名单外用户不允许上传",
)));
"result" => "failed",
"code" => 205,
"message" => "黑名单内或白名单外用户不允许上传",
), JSON_UNESCAPED_UNICODE));
}
}
$token = preg_replace('/[\W]/', '', $_POST['token']); // 获取Token并过滤非字母数字删除空格;
// 获取Token并过滤非字母数字, 删除空格
$token = preg_replace('/[\W]/', '', $_POST['token']);
// 检查api合法性
check_api($token);
$tokenID = $tokenList[$token]['id'];
$handle = new Upload($_FILES['image'], 'zh_CN');
// 分片上传
if (!$config['chunks']) {
$handle = new Upload($_FILES['image'], 'zh_CN');
} else {
$chunk = chunk($_POST['name']);
$handle = new Upload($chunk, 'zh_CN');
}
if ($handle->uploaded) {
// 允许上传的mime类型
if ($config['allowed'] === 1) {
if ($config['allowed']) {
$handle->allowed = array('image/*');
}
@@ -61,7 +70,8 @@ if ($handle->uploaded) {
"result" => "failed",
"code" => 205,
"message" => "请勿上传非法文件",
)
),
JSON_UNESCAPED_UNICODE
));
}
}
@@ -90,25 +100,12 @@ if ($handle->uploaded) {
$handle->webp_quality = $config['compress_ratio'];
// JPEG 图像的压缩质量 1-100
$handle->jpeg_quality = $config['compress_ratio'];
/* 等比例缩减图片 放到前端了*/
/*
if ($config['imgRatio']) {
$handle->image_resize = true;
$handle->image_x = $config['image_x'];
$handle->image_y = $config['image_y'];
// 如果调整后的图像大于原始图像,则取消调整大小,以防止放大
$handle->image_no_enlarging = true;
}
*/
// 默认目录
$Img_path = config_path();
if ($config['token_path_status'] == 1) {
//Token分离
if ($config['token_path_status']) {
$Img_path = config_path($tokenID . date('/Y/m/d/'));
}
// 存储图片路径:images/201807/
$handle->process(APP_ROOT . $Img_path);
@@ -120,27 +117,23 @@ if ($handle->uploaded) {
$imageUrl = rand_imgurl() . $pathIMG;
// 后续处理地址
$processUrl = $config['domain'] . $pathIMG;
// 隐藏config文件中的path目录,需要搭配网站设置
if ($config['hide_path'] == 1) {
if ($config['hide_path']) {
$imageUrl = str_replace($config['path'], '/', $imageUrl);
}
// 源图保护 key值是由crc32加密的hide_key
if ($config['hide'] == 1) {
if ($config['hide']) {
$imageUrl = $config['domain'] . '/app/hide.php?key=' . urlHash($pathIMG, 0, crc32($config['hide_key']));
}
// 删除文件链接
if ($config['show_user_hash_del']) {
$delUrl = $config['domain'] . '/app/del.php?hash=' . urlHash($pathIMG, 0);
} else {
$delUrl = "Admin closed user delete";
}
// 当设置访问生成缩略图时自动生成 2022-12-30 修正 2023-01-30
$handleThumb = $config['domain'] . '/app/thumb.php?img=' . $pathIMG;
if ($config['thumbnail'] == 2) {
if ($config['thumbnail'] === 2) {
// 自定义缩略图长宽
$handle->image_resize = true;
$handle->image_x = $config['thumbnail_w'];
@@ -160,8 +153,8 @@ if ($handle->uploaded) {
"srcName" => $handle->file_src_name_body,
"thumb" => $handleThumb,
"del" => $delUrl,
"ID" => $tokenID, // 202-02-11 增加返回Token ID
"message" => "success",
"id" => $tokenID, // 2023-02-11 增加返回Token ID
"message" => "success", // 2023-04-22 增加返回信息
// "memory" => getDistUsed(memory_get_peak_usage()), // 占用内存 2023-02-12
);
echo json_encode($reJson, JSON_UNESCAPED_UNICODE);
@@ -171,6 +164,8 @@ if ($handle->uploaded) {
$reJson = array(
"result" => "failed",
"code" => 206,
"srcName" => $handle->file_src_name_body, // 2023-04-03 原始上传文件名称
"id" => $tokenID, // 2023-04-03 增加 Token ID
"message" => $handle->error,
"memory" => getDistUsed(memory_get_peak_usage()), // 占用内存 2023-02-12
// 'log' => $handle->log, // 仅用作调试用
@@ -180,8 +175,6 @@ if ($handle->uploaded) {
}
/** 后续处理 */
// 上传至其他位置
// @any_upload($pathIMG, APP_ROOT . $pathIMG, 'upload');
// 使用fastcgi_finish_request操作
if (function_exists('fastcgi_finish_request')) fastcgi_finish_request();
// 同IP上传日志
@@ -194,6 +187,8 @@ if ($handle->uploaded) {
@water($handle->file_dst_pathname);
// 压缩
@process_compress($handle->file_dst_pathname);
// 上传至其他位置
@any_upload($pathIMG, APP_ROOT . $pathIMG, 'upload');
unset($handle);
}

View File

@@ -5,11 +5,10 @@
* 2022年2月22日11:41:38
* @author Icret
*/
require_once '../app/function.php';
require_once '../app/chart.php';
// 检查是否开启查询
if ($config['public'] == 0) die('开放数据接口已关闭!');
if ($config['public'] === 0) die('开放数据接口已关闭!');
// 获得get值
$show = (empty($_GET['show'])) ? die('没有参数!') : htmlspecialchars($_GET['show']);