You've already forked EasyImages2.0
mirror of
https://github.com/icret/EasyImages2.0.git
synced 2025-12-13 11:43:58 +08:00
v2.4.8
This commit is contained in:
102
application/FsockService.php
Executable file
102
application/FsockService.php
Executable file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 异步 执行程序
|
||||
* param string $path 异步url 地址
|
||||
* param array $postData 传递的参数
|
||||
* param string $method 请求方式
|
||||
* param string $url 请求地址
|
||||
* return bool
|
||||
*/
|
||||
function request_asynchronous($path, $method = "POST", $postData = array(), $url = '')
|
||||
{
|
||||
if (empty($path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($url) {
|
||||
$matches = parse_url($url);
|
||||
$host = $matches['host'];
|
||||
//$path = $matches['path'] ? $matches['path'] . ($matches['query'] ? '?' . $matches['query'] : '') : '/';
|
||||
if ($matches['scheme'] == 'https') { //判断是否使用HTTPS
|
||||
$transports = 'ssl://'; //如使用HTTPS则使用SSL协议
|
||||
$port = !empty($matches['port']) ? $matches['port'] : 443; //如使用HTTPS端口使用443
|
||||
} else {
|
||||
$transports = 'tcp://'; //如没有使用HTTPS则使用tcp协议
|
||||
$port = !empty($matches['port']) ? $matches['port'] : 80; //如没有使用HTTPS则使用80端口
|
||||
}
|
||||
} else {
|
||||
$port = 443;
|
||||
$transports = 'ssl://';
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
}
|
||||
|
||||
$errNo = 0;
|
||||
$errStr = '';
|
||||
$timeout = 60;
|
||||
$fp = '';
|
||||
if (function_exists('fsockopen')) {
|
||||
$fp = fsockopen(($transports . $host), $port, $errno, $errStr, $timeout);
|
||||
} elseif (function_exists('pfsockopen')) {
|
||||
$fp = pfsockopen($transports . $host, $port, $errNo, $errStr, $timeout);
|
||||
} elseif (function_exists('stream_socket_client')) {
|
||||
$fp = stream_socket_client($transports . $host . ':' . $port, $errNo, $errStr, $timeout);
|
||||
}
|
||||
|
||||
if (!$fp) {
|
||||
return false;
|
||||
}
|
||||
|
||||
stream_set_blocking($fp, 0); //开启非阻塞模式
|
||||
stream_set_timeout($fp, 3); //设置超时时间(s)
|
||||
|
||||
$date = [];
|
||||
if ($postData) {
|
||||
//处理文件
|
||||
foreach ($postData as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$date[$key] = serialize($value);
|
||||
} else {
|
||||
$date[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($method == "GET") {
|
||||
$query = $date ? http_build_query($date) : '';
|
||||
$path .= "?" . $query;
|
||||
} else {
|
||||
$query = json_encode($date);
|
||||
}
|
||||
|
||||
//http消息头
|
||||
$out = $method . " " . $path . " HTTP/1.1\r\n";
|
||||
$out .= "HOST: " . $host . "\r\n";
|
||||
if ($method == "POST") {
|
||||
$out .= "Content-Length:" . strlen($query) . "\r\n";
|
||||
}
|
||||
$out .= "Accept: application/json, text/plain, */*\r\n";
|
||||
$out .= "Access-Control-Allow-Credentials: true\r\n";
|
||||
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
|
||||
$out .= "Connection: Close\r\n\r\n";
|
||||
if ($method == "POST") {
|
||||
$out .= $query;
|
||||
}
|
||||
|
||||
fputs($fp, $out);
|
||||
usleep(20000);
|
||||
//忽略执行结果
|
||||
/*while (!feof($fp)) {
|
||||
echo fgets($fp, 128);
|
||||
}*/
|
||||
fclose($fp);
|
||||
|
||||
return true;
|
||||
}
|
||||
/*
|
||||
$p = array(
|
||||
'test'=>1222,
|
||||
'test1'=>2222,
|
||||
);
|
||||
var_dump(request_asynchronous('/test.php', 'GET', $p, 'https://png.cm'));
|
||||
*/
|
||||
@@ -95,7 +95,7 @@ class Imgcompress
|
||||
private function _saveImage($dstImgName)
|
||||
{
|
||||
if (empty($dstImgName)) return false;
|
||||
$allowImgs = array('.jpg', '.jpeg', '.png', '.bmp', '.wbmp', '.gif','webp'); //如果目标图片名有后缀就用目标图片扩展名 后缀,如果没有,则用源图的扩展名
|
||||
$allowImgs = array('.jpg', '.jpeg', '.png', '.bmp', '.wbmp', '.gif','.webp'); // 如果目标图片名有后缀就用目标图片扩展名 后缀,如果没有,则用源图的扩展名
|
||||
$dstExt = strrchr($dstImgName, ".");
|
||||
$sourseExt = strrchr($this->src, ".");
|
||||
if (!empty($dstExt)) $dstExt = strtolower($dstExt);
|
||||
|
||||
@@ -604,6 +604,7 @@ function moderatecontent_json($img, $url = null)
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36');
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
@@ -716,14 +717,12 @@ function checkImg($imageUrl, $type = 1)
|
||||
$old_path = APP_ROOT . str_replace($config['imgurl'], '', $imageUrl); // 提交网址中的文件路径 /i/2021/10/29/p8vypd.png
|
||||
$name = date('Y_m_d') . '_' . basename($imageUrl); // 文件名 2021_10_30_p8vypd.png
|
||||
$new_path = APP_ROOT . $config['path'] . 'suspic/' . $name; // 新路径含文件名
|
||||
$cache_dir = APP_ROOT . $config['path'] . 'suspic/'; // suspic路径
|
||||
$suspic_dir = APP_ROOT . $config['path'] . 'suspic/'; // suspic路径
|
||||
|
||||
if (is_dir($cache_dir)) { // 创建suspic目录并移动
|
||||
rename($old_path, $new_path);
|
||||
} else {
|
||||
mkdir($cache_dir, 0777, true);
|
||||
rename($old_path, $new_path);
|
||||
if (!is_dir($suspic_dir)) { // 创建suspic目录并移动
|
||||
mkdir($suspic_dir, 0777, true);
|
||||
}
|
||||
rename($old_path, $new_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/function.php';
|
||||
require_once __DIR__ . '/WaterMask.php';
|
||||
|
||||
// 压缩图片与图片鉴黄
|
||||
function process($filePath, $absolutePath)
|
||||
function compress($absolutePath)
|
||||
{
|
||||
global $config;
|
||||
// 压缩图片 后压缩模式,不影响前台输出速度
|
||||
@@ -18,14 +19,59 @@ function process($filePath, $absolutePath)
|
||||
flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置水印
|
||||
function water($source)
|
||||
{
|
||||
global $config;
|
||||
|
||||
// 文字水印
|
||||
if ($config['watermark'] == 1) {
|
||||
// 过滤gif
|
||||
if (isAnimatedGif($source) === 0) {
|
||||
$arr = [
|
||||
# 水印图片路径(如果不存在将会被当成是字符串水印)
|
||||
'res' => $config['waterText'],
|
||||
# 水印显示位置
|
||||
'pos' => $config['waterPosition'],
|
||||
# 不指定name(会覆盖原图,也就是保存成thumb.jpeg)
|
||||
'name' => $source,
|
||||
'font' => APP_ROOT . $config['textFont'],
|
||||
'fontSize' => $config['textSize'],
|
||||
'color' => $config['textColor'],
|
||||
];
|
||||
Imgs::setWater($source, $arr);
|
||||
}
|
||||
}
|
||||
|
||||
// 图片水印
|
||||
if ($config['watermark'] == 2) {
|
||||
// 过滤gif
|
||||
if (isAnimatedGif($source) === 0) {
|
||||
$arr = [
|
||||
# 水印图片路径(如果不存在将会被当成是字符串水印)
|
||||
'res' => APP_ROOT . $config['waterImg'],
|
||||
# 水印显示位置
|
||||
'pos' => $config['waterPosition'],
|
||||
# 不指定name(会覆盖原图,也就是保存成thumb.jpeg)
|
||||
'name' => $source,
|
||||
];
|
||||
Imgs::setWater($source, $arr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function process_checkImg($imgurl)
|
||||
{
|
||||
global $config;
|
||||
// 图片违规检查
|
||||
if ($config['checkImg'] == 1) {
|
||||
@checkImg($config['imgurl'] . $filePath, 1);
|
||||
checkImg($imgurl, 1);
|
||||
}
|
||||
|
||||
if ($config['checkImg'] == 2) {
|
||||
@checkImg($config['imgurl'] . $filePath, 2);
|
||||
checkImg($imgurl, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,3 +128,12 @@ function write_log($filePath, $sourceName, $absolutePath, $fileSize, $from = "We
|
||||
cache_write($logFileName, $log, 'logs');
|
||||
*/
|
||||
}
|
||||
|
||||
if (isset($_GET['auth'])) {
|
||||
$checkAuth = md5($config['domain'] . $config['password']);
|
||||
|
||||
// 鉴权
|
||||
if ($_GET['auth'] == $checkAuth) {
|
||||
process_checkImg($_GET['img']);
|
||||
}
|
||||
}
|
||||
|
||||
138
application/upload.php
Executable file
138
application/upload.php
Executable file
@@ -0,0 +1,138 @@
|
||||
|
||||
<?php
|
||||
require __DIR__ . '/function.php';
|
||||
require __DIR__ . '/class.upload.php';
|
||||
|
||||
// 检查登录
|
||||
if ($config['mustLogin']) {
|
||||
checkLogin();
|
||||
}
|
||||
|
||||
// 黑/白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" => "黑名单内或白名单外用户不允许上传",
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
$handle = new Upload($_FILES['file'], 'zh_CN');
|
||||
|
||||
if ($handle->uploaded) {
|
||||
// 允许上传的mime类型
|
||||
$handle->allowed = array('image/*');
|
||||
// 文件命名
|
||||
$handle->file_new_name_body = imgName($handle->file_src_name_body);
|
||||
// 最大上传限制
|
||||
//$handle->file_max_sizes = $config['maxSize'];
|
||||
// 最大宽度
|
||||
$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'];
|
||||
|
||||
/* 等比例缩减图片 放到前端了
|
||||
if ($config['imgRatio']) {
|
||||
$handle->image_resize = true;
|
||||
$handle->image_x = $config['image_x'];
|
||||
$handle->image_y = $config['image_y'];
|
||||
}
|
||||
*/
|
||||
|
||||
// 存储图片路径:images/201807/
|
||||
$handle->process(APP_ROOT . config_path());
|
||||
|
||||
/*
|
||||
// 创建缩略图 开启后会个别返回文件失败,暂时没找到替代方案,如果启用此项目,需要将list.php中的get_online_thumbnail改成return_thumbnail_images函数
|
||||
if ($config['thumbnail']) {
|
||||
@creat_thumbnail_images($handle->file_dst_name);
|
||||
}
|
||||
*/
|
||||
|
||||
// 图片完整相对路径:/i/2021/05/03/k88e7p.jpg
|
||||
if ($handle->processed) {
|
||||
header('Content-type:text/json');
|
||||
// 上传成功后返回json数据
|
||||
$imageUrl = $config['imgurl'] . config_path() . $handle->file_dst_name;
|
||||
|
||||
// 关闭上传后显示加密删除链接
|
||||
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";
|
||||
}
|
||||
} else {
|
||||
$delUrl = "Admin closed delete";
|
||||
}
|
||||
|
||||
$reJson = array(
|
||||
"result" => "success",
|
||||
"code" => 200,
|
||||
"url" => $imageUrl,
|
||||
"del" => $delUrl,
|
||||
);
|
||||
echo json_encode($reJson);
|
||||
$handle->clean();
|
||||
} else {
|
||||
// 上传错误 code:400 客户端文件有问题
|
||||
$reJson = array(
|
||||
"result" => "failed",
|
||||
"code" => 400,
|
||||
"message" => $handle->error,
|
||||
);
|
||||
unset($handle);
|
||||
header('Content-Type:application/json; charset=utf-8');
|
||||
unset($handle);
|
||||
exit(json_encode($reJson, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
|
||||
/** 后续处理 */
|
||||
require __DIR__ . '/process.php';
|
||||
/*
|
||||
require __DIR__ . '/FsockService.php';
|
||||
|
||||
// 使用fosksock异步申请鉴黄
|
||||
if ($config['checkImg']) {
|
||||
$process = array(
|
||||
'auth' => md5($config['domain'] . $config['password']),
|
||||
'img' => $imageUrl
|
||||
);
|
||||
@request_asynchronous('/application/process.php', 'GET', $process, $config['domain']);
|
||||
}
|
||||
*/
|
||||
// 普通模式鉴黄
|
||||
process_checkImg($imageUrl);
|
||||
|
||||
// 使用fastcgi_finish_request操作
|
||||
if (function_exists('fastcgi_finish_request')) {
|
||||
fastcgi_finish_request();
|
||||
// 日志
|
||||
if ($config['upload_logs']) @write_log(config_path() . $handle->file_dst_name, $handle->file_src_name, $handle->file_dst_pathname, $handle->file_src_size);
|
||||
// 水印
|
||||
@water($handle->file_dst_pathname);
|
||||
// 压缩
|
||||
@compress($handle->file_dst_pathname);
|
||||
} else {
|
||||
// 日志
|
||||
if ($config['upload_logs']) write_log(config_path() . $handle->file_dst_name, $handle->file_src_name, $handle->file_dst_pathname, $handle->file_src_size);
|
||||
// 水印
|
||||
@water($handle->file_dst_pathname);
|
||||
// 压缩
|
||||
@compress($handle->file_dst_pathname);
|
||||
}
|
||||
|
||||
|
||||
unset($handle);
|
||||
}
|
||||
Reference in New Issue
Block a user