2021-05-22 03:27:53 +00:00
|
|
|
|
|
2021-03-23 12:58:16 +00:00
|
|
|
|
<?php
|
2021-11-09 03:43:23 +00:00
|
|
|
|
require __DIR__ . '/application/function.php';
|
|
|
|
|
require APP_ROOT . '/application/class.upload.php';
|
|
|
|
|
require APP_ROOT . '/application/WaterMask.php';
|
2021-03-23 12:58:16 +00:00
|
|
|
|
|
2022-01-27 09:25:46 +00:00
|
|
|
|
// 检查登录
|
|
|
|
|
if ($config['mustLogin']) {
|
|
|
|
|
checkLogin();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-19 17:55:20 +00:00
|
|
|
|
// 黑/白IP名单上传
|
|
|
|
|
if ($config['check_ip']) {
|
|
|
|
|
if (checkIP(null, $config['check_ip_list'], $config['check_ip_model'])) {
|
|
|
|
|
// 上传错误 code:403 未授权IP
|
|
|
|
|
exit(json_encode(array(
|
|
|
|
|
"result" => "failed",
|
|
|
|
|
"code" => 403,
|
|
|
|
|
"message" => "黑名单内或白名单外用户不允许上传",
|
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 12:58:16 +00:00
|
|
|
|
$handle = new Upload($_FILES['file'], 'zh_CN');
|
|
|
|
|
|
|
|
|
|
if ($handle->uploaded) {
|
|
|
|
|
// 允许上传的mime类型
|
|
|
|
|
$handle->allowed = array('image/*');
|
|
|
|
|
// 文件命名
|
2022-01-03 22:31:05 +00:00
|
|
|
|
$handle->file_new_name_body = imgName($handle->file_src_name_body);
|
2021-03-23 12:58:16 +00:00
|
|
|
|
// 最大上传限制
|
2021-05-08 07:35:27 +00:00
|
|
|
|
//$handle->file_max_sizes = $config['maxSize'];
|
2021-03-23 12:58:16 +00:00
|
|
|
|
// 最大宽度
|
|
|
|
|
$handle->image_max_width = $config['maxWidth'];
|
|
|
|
|
// 最大高度
|
|
|
|
|
$handle->image_max_height = $config['maxHeight'];
|
|
|
|
|
// 最小宽度
|
|
|
|
|
$handle->image_min_width = $config['minWidth'];
|
|
|
|
|
// 最小高度
|
|
|
|
|
$handle->image_min_height = $config['minHeight'];
|
|
|
|
|
// 转换图片为指定格式
|
|
|
|
|
$handle->image_convert = $config['imgConvert'];
|
2021-05-22 03:27:53 +00:00
|
|
|
|
|
|
|
|
|
/* 等比例缩减图片 放到前端了
|
2021-03-23 12:58:16 +00:00
|
|
|
|
if ($config['imgRatio']) {
|
2021-03-28 11:42:59 +00:00
|
|
|
|
$handle->image_resize = true;
|
2021-03-23 12:58:16 +00:00
|
|
|
|
$handle->image_x = $config['image_x'];
|
2021-03-28 11:42:59 +00:00
|
|
|
|
$handle->image_y = $config['image_y'];
|
2021-03-23 12:58:16 +00:00
|
|
|
|
}
|
2021-05-08 07:35:27 +00:00
|
|
|
|
*/
|
2021-05-22 03:27:53 +00:00
|
|
|
|
|
2021-03-23 12:58:16 +00:00
|
|
|
|
// 存储图片路径:images/201807/
|
2021-05-22 03:27:53 +00:00
|
|
|
|
$handle->process(APP_ROOT . config_path());
|
2021-03-23 12:58:16 +00:00
|
|
|
|
|
|
|
|
|
// 设置水印
|
|
|
|
|
if ($config['watermark'] > 0) {
|
|
|
|
|
switch ($config['watermark']) {
|
|
|
|
|
case 1: // 文字水印 过滤gif
|
|
|
|
|
if (isAnimatedGif($handle->file_src_pathname) === 0) {
|
|
|
|
|
$arr = [
|
|
|
|
|
# 水印图片路径(如果不存在将会被当成是字符串水印)
|
2021-05-04 12:54:59 +00:00
|
|
|
|
'res' => $config['waterText'],
|
2021-03-23 12:58:16 +00:00
|
|
|
|
# 水印显示位置
|
2021-05-04 12:54:59 +00:00
|
|
|
|
'pos' => $config['waterPosition'],
|
2021-03-23 12:58:16 +00:00
|
|
|
|
# 不指定name(会覆盖原图,也就是保存成thumb.jpeg)
|
2021-05-04 12:54:59 +00:00
|
|
|
|
'name' => $handle->file_dst_pathname,
|
2021-11-09 03:43:23 +00:00
|
|
|
|
'font' => APP_ROOT . $config['textFont'],
|
2021-03-23 12:58:16 +00:00
|
|
|
|
'fontSize' => $config['textSize'],
|
|
|
|
|
'color' => $config['textColor'],
|
|
|
|
|
];
|
|
|
|
|
Imgs::setWater($handle->file_dst_pathname, $arr);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2: // 图片水印
|
|
|
|
|
if (isAnimatedGif($handle->file_src_pathname) === 0) {
|
|
|
|
|
$arr = [
|
|
|
|
|
# 水印图片路径(如果不存在将会被当成是字符串水印)
|
2021-11-09 03:43:23 +00:00
|
|
|
|
'res' => APP_ROOT . $config['waterImg'],
|
2021-03-23 12:58:16 +00:00
|
|
|
|
# 水印显示位置
|
2021-05-04 12:54:59 +00:00
|
|
|
|
'pos' => $config['waterPosition'],
|
2021-03-23 12:58:16 +00:00
|
|
|
|
# 不指定name(会覆盖原图,也就是保存成thumb.jpeg)
|
2021-05-04 12:54:59 +00:00
|
|
|
|
'name' => $handle->file_dst_pathname,
|
2021-03-23 12:58:16 +00:00
|
|
|
|
];
|
|
|
|
|
Imgs::setWater($handle->file_dst_pathname, $arr);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
echo $handle->error;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-22 03:27:53 +00:00
|
|
|
|
|
2022-01-02 21:43:03 +00:00
|
|
|
|
/*
|
|
|
|
|
// 创建缩略图 开启后会个别返回文件失败,暂时没找到替代方案,如果启用此项目,需要将list.php中的get_online_thumbnail改成return_thumbnail_images函数
|
|
|
|
|
if ($config['thumbnail']) {
|
|
|
|
|
@creat_thumbnail_images($handle->file_dst_name);
|
|
|
|
|
}
|
|
|
|
|
*/
|
2022-01-03 22:43:03 +00:00
|
|
|
|
|
2021-05-04 12:54:59 +00:00
|
|
|
|
// 图片完整相对路径:/i/2021/05/03/k88e7p.jpg
|
2021-03-23 12:58:16 +00:00
|
|
|
|
if ($handle->processed) {
|
|
|
|
|
header('Content-type:text/json');
|
|
|
|
|
// 上传成功后返回json数据
|
2021-05-22 03:27:53 +00:00
|
|
|
|
$imageUrl = $config['imgurl'] . config_path() . $handle->file_dst_name;
|
|
|
|
|
|
2022-01-27 09:25:46 +00:00
|
|
|
|
// 关闭上传后显示加密删除链接
|
|
|
|
|
if ($config['show_user_hash_del']) {
|
|
|
|
|
// 判断PHP版本启用删除
|
|
|
|
|
if (PHP_VERSION >= '7') {
|
|
|
|
|
$delUrl = $config['domain'] . '/application/del.php?hash=' . urlHash(config_path() . $handle->file_dst_name, 0);
|
|
|
|
|
} else {
|
|
|
|
|
$delUrl = "Sever PHP version lower 7.0";
|
|
|
|
|
}
|
2021-05-22 03:27:53 +00:00
|
|
|
|
} else {
|
2022-01-27 09:25:46 +00:00
|
|
|
|
$delUrl = "Admin closed delete";
|
2021-05-22 03:27:53 +00:00
|
|
|
|
}
|
2021-05-04 12:54:59 +00:00
|
|
|
|
|
2021-03-23 12:58:16 +00:00
|
|
|
|
$reJson = array(
|
2022-01-02 12:20:53 +00:00
|
|
|
|
"result" => "success",
|
|
|
|
|
"code" => 200,
|
2022-01-01 07:40:23 +00:00
|
|
|
|
"url" => $imageUrl,
|
|
|
|
|
"del" => $delUrl,
|
2021-03-23 12:58:16 +00:00
|
|
|
|
);
|
|
|
|
|
echo json_encode($reJson);
|
|
|
|
|
$handle->clean();
|
|
|
|
|
} else {
|
2022-01-19 17:55:20 +00:00
|
|
|
|
// 上传错误 code:400 客户端文件有问题
|
2021-03-23 12:58:16 +00:00
|
|
|
|
$reJson = array(
|
2022-01-02 12:20:53 +00:00
|
|
|
|
"result" => "failed",
|
2022-01-19 17:55:20 +00:00
|
|
|
|
"code" => 400,
|
2022-01-01 07:40:23 +00:00
|
|
|
|
"message" => $handle->error,
|
2021-03-23 12:58:16 +00:00
|
|
|
|
);
|
2022-01-02 12:20:53 +00:00
|
|
|
|
unset($handle);
|
|
|
|
|
header('Content-Type:application/json; charset=utf-8');
|
|
|
|
|
exit(json_encode($reJson, JSON_UNESCAPED_UNICODE));
|
2021-03-23 12:58:16 +00:00
|
|
|
|
}
|
2021-05-22 03:27:53 +00:00
|
|
|
|
|
2022-01-19 17:55:20 +00:00
|
|
|
|
// 后续处理
|
|
|
|
|
require_once APP_ROOT . '/application/process.php';
|
|
|
|
|
// 日志
|
2022-01-01 07:40:23 +00:00
|
|
|
|
if ($config['upload_logs']) {
|
|
|
|
|
@write_log(config_path() . $handle->file_dst_name, $handle->file_src_name, $handle->file_dst_pathname, $handle->file_src_size);
|
2021-11-14 15:25:21 +00:00
|
|
|
|
}
|
2022-01-19 17:55:20 +00:00
|
|
|
|
// 压缩|鉴黄
|
|
|
|
|
process(config_path() . $handle->file_dst_name, $handle->file_dst_pathname);
|
2021-11-09 03:43:23 +00:00
|
|
|
|
|
2022-01-01 07:40:23 +00:00
|
|
|
|
unset($handle);
|
2021-05-04 12:54:59 +00:00
|
|
|
|
}
|