更新上传组件--支持PHP8

pull/18/head
icret 2021-10-27 21:36:58 +08:00
parent fb46892b91
commit 54c4e6ff4a
7 changed files with 517 additions and 0 deletions

221
api/api-web.php Executable file
View File

@ -0,0 +1,221 @@
<?php
/*
* API 页面管理
*/
require_once '../libs/header.php';
require_once APP_ROOT . '/config/api_key.php';
require_once APP_ROOT . '/api/libs//apiFunction.php';
// 检测登录
if (!is_online()) {
checkLogin();
}
// 查找用户ID或者Token
if (isset($_POST['radio'])) {
if ($_POST['radio'] == 'id') {
$radio_value = '用户token' . getIDToken($_POST['radio-value']);
} elseif ($_POST['radio'] == 'token') {
$radio_value = '用户ID' . getID($_POST['radio-value']);
} else {
$radio_value = null;
}
}
// 删除非空目录
if (isset($_POST['delDir'])) {
$delDir = APP_ROOT . $config['path'] . $_POST['delDir'];
if (deldir($delDir)) {
echo '
<script> new $.zui.Messager("删除成功!", {type: "success" // 定义颜色主题
}).show();</script>';
header("refresh:1;"); // 1s后刷新当前页面
} else {
echo '
<script> new $.zui.Messager("删除失败!", {type: "danger" // 定义颜色主题
}).show();</script>';
header("refresh:1;"); // 1s后刷新当前页面
}
}
?>
<div class="container">
</div class="row">
<div class="col-md-12">
<div class="alert alert-primary">
<h3 style="text-align:center">EasyImage2.0 快捷操作中心</h2>
<hr />
<h5>目录保存以 /// 递进,非必要请勿修改!否则会导致部分操作不可用;</h5>
<h5>本人仅为程序开源创作,如非法网站使用与本人无关,请勿用于非法用途;</h5>
<h5>请为本人博客<a href="https://www.545141.com/" target="_blank">www.545141.com</a>加上网址链接,谢谢支持。作为开发者你可以对相应的后台功能进行扩展(增删改相应代码),但请保留代码中相关来源信息(例如:本人博客,邮箱等)。</h5>
<p>
<button type="button" class="btn btn-mini" data-toggle="collapse" data-target="#collapseExample">服务信息<i class="icon icon-hand-down"></i></button>
</p>
<div class="collapse" id="collapseExample">
<div class="bg-danger with-padding">
<h5>系统信息</h5>
<hr />
<p>服务器系统:<?PHP echo php_uname('s') . ' <small class="text-muted">' . php_uname() . '</small>'; ?></p>
<p>WEB服务<?PHP echo $_SERVER['SERVER_SOFTWARE']; ?></p>
<p>服务器IP<?PHP echo GetHostByName($_SERVER['SERVER_NAME']) ?></p>
<p>系统时间:<?PHP echo date("Y-m-d G:i:s"); ?></p>
<p>已用空间:<?php echo getDistUsed(disk_total_space(__DIR__) - disk_free_space(__DIR__)) . ' 剩余空间:' . getDistUsed(disk_free_space(__DIR__)); ?></p>
<h5>PHP信息</h5>
<hr />
<p>PHP版本<?php echo phpversion(); ?></p>
<p>GD版本<?php echo (gd_info()["GD Version"]); ?></p>
<p>PHP上传限制<?PHP echo get_cfg_var("upload_max_filesize"); ?></p>
<p>POST上传限制<?php echo ini_get('post_max_size'); ?></p>
<p>PHP最长执行时间<?PHP echo get_cfg_var("max_execution_time") . ""; ?></p>
<p>PHP允许占用内存<?PHP echo get_cfg_var("memory_limit") . "M "; ?></p>
<h5>我的信息</h5>
<hr />
<p>浏览器:<?php echo $_SERVER['HTTP_USER_AGENT']; ?></p>
<p>访问者IP<?php echo $_SERVER["REMOTE_ADDR"]; ?></p>
<h5>图床信息</h5>
<hr />
<p><?php
$yesterday = date("Y/m/d/", strtotime("-1 day"));
echo '今日上传:' . getFileNumber(APP_ROOT . config_path()) . ' 昨日上传:' . getFileNumber(APP_ROOT . $config['path'] . $yesterday); ?>
</p>
<p>当前版本:<?php echo $config['version']; ?>Github版本<a href="https://github.com/icret/EasyImages2.0/releases" target="_blank"><?php echo getVersion(); ?></a></p>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="col-md-4">
<form class="form-condensed" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<label for="exampleInputMoney1">
新Token需按要求填入
<code>
/config/api_key.php
</code>
才生效
</label>
<div class="input-group">
<span class="input-group-addon">
New Token
</span>
<input type="text" class="form-control" id="exampleInputMoney1" value="<?php echo privateToken(); ?>">
</div>
</div>
<div class="col-md-4">
<form></form>
<form class="form-condensed" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<div class="form-group">
<label for="exampleInputAccount6">根据ID/Token查找用户信息</label>
<input type="text" name="radio-value" id="exampleInputAccount6" class="form-control" placeholder="输入信息" value="<?php echo @$radio_value; ?>">
<div class="radio-primary"><input type="radio" name="radio" value="id" id="primaryradio1" checked="checked"><label for="primaryradio1">根据ID查找用户Token</label></div>
<div class="radio-primary"><input type="radio" name="radio" value="token" id="primaryradio2"><label for="primaryradio2">根据Token查找用户ID</label></div>
<button type="submit" class="btn btn-mini btn-primary">
查找
</button>
</div>
</form>
</div>
<div class="col-md-4">
<div id="delimgurl"></div>
<div id="title"></div>
<form class="form-condensed" method="get" action="del.php" id="form" name="delForm" onSubmit="getStr();" target="_blank">
<div class="form-group">
<label for="del">
删除图片
</label>
<input type="url" name="url" class="form-control" id="del" placeholder="请输入图片链接" />
</div>
<label>格式:<code>https://i1.100024.xyz/i/2021/05/04/10fn9ei.jpg</code></label>
<input type="submit" class="btn btn-mini btn-primary" value="删除" />
</form>
</div>
</div>
<div class="col-md-12">
<div class="col-md-4">
<form action="../libs/compressing.php" method="post" target="_blank">
<div class="form-group">
<label for="exampleInputInviteCode1">压缩文件夹内图片(格式2021/05/10/)</label>
<input type="text" class="form-control form-date" placeholder="" name="folder" value="<?php echo date('Y/m/d/'); ?>" readonly="">
</div>
<div class="radio">
<label>
<input type="radio" name="type" value="Imgcompress" checked="checked"> 使用本地压缩(默认上传已压缩,不需重复压缩)
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="type" value="TinyImg"> 使用TinyImag压缩需要申请key)
</label>
</div>
<div>
<label>
* 如果页面长时间没有响应,表示正面正在压缩!
</label>
<label>
两种压缩均为不可逆,并且非常占用硬件资源。
</label>
</div>
<button type="submit" class="btn btn-mini btn-success">开始压缩</button>
</form>
</div>
<div class="col-md-4">
<table class="table table-hover table-bordered table-condensed table-responsive">
<thead>
<tr>
<th>当前可用Token列表</th>
</tr>
</thead>
<tbody>
<?php
foreach ($tokenList as $value) {
echo '<tr><td>' . $value . '</td></tr>';
}
?>
</tbody>
</table>
</div>
<div class="col-md-4">
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<div class="form-group">
<label for="exampleInputInviteCode1" style="color:red">删除所选日期文件夹(删除之后无法恢复!):</label>
<input type="text" class="form-control form-date" name="delDir" value="<?php echo date('Y/m/d/'); ?>" readonly="">
</div>
<button type="submit" class="btn btn-mini btn-danger" onClick="return confirm('确认要删除?\n* 删除文件夹后将无法恢复!');">删除目录</button>
</form>
</div>
</div>
<link href="<?php static_cdn(); ?>/public/static/zui/lib/datetimepicker/datetimepicker.min.css" rel="stylesheet">
<script src="<?php static_cdn(); ?>/public/static/zui/lib/datetimepicker/datetimepicker.min.js"></script>
<script>
// 动态显示要删除的图片
var oBtn = document.getElementById('del');
var oTi = document.getElementById('title');
if ('oninput' in oBtn) {
oBtn.addEventListener("input", getWord, false);
} else {
oBtn.onpropertychange = getWord;
}
function getWord() {
var delimgurl = document.getElementById("delimgurl");
delimgurl.innerHTML += '<img src="' + oBtn.value + '" width="200" class="img-rounded" /><br />';
}
// 仅选择日期
$(".form-date").datetimepicker({
weekStart: 1,
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
minView: 2,
forceParse: 0,
format: "yyyy/mm/dd/"
});
// Title
document.title = "管理中心 - <?php echo $config['title']; ?>";
</script>
<?php require_once APP_ROOT . '/libs/footer.php';

38
api/apiTest/index.php Executable file
View File

@ -0,0 +1,38 @@
<?php
echo '<title> - EasyImage2.0</title>';
require_once '../../libs/function.php';
require_once APP_ROOT . '/libs/header.php';
require_once APP_ROOT . '/config/api_key.php';
// 如果关闭Api上传并且没有登录的情况下关闭测试接口
if (!$config['apiStatus'] and !is_online()) {
exit('<script>
new $.zui.Messager("Api关闭请登录", {type: "danger" // 定义颜色主题
}).show();
// 延时2s跳转
window.setTimeout("window.location=\'/../libs/login.php \'",2000);
</script>');
}
?>
<div class="container">
</div class="row">
<div class="col-md-12">
<h4>测试Token<code><?php echo $tokenList['1']; ?></code></h4>
<form action="../index.php" method="post" enctype="multipart/form-data" class="form-inline" target="_blank">
<div class="form-group">
<input type="file" name="image" accept="image/*" class="form-control" />
</div>
<div class="form-group">
<input type="text" name="token" placeholder="请输入Token" class="form-control" />
</div>
<button type="submit" class="btn btn-primary">上传</button>
</form>
</div>
</div>
</div>
<script>
document.title = "API图片上传测试 - <?php echo $config['title']; ?>";
</script>
<?php require_once APP_ROOT . '/libs/footer.php';

81
api/del.php Executable file
View File

@ -0,0 +1,81 @@
<?php
/**
* 删除文件页面
*/
require_once '../libs/header.php';
require_once APP_ROOT . '/libs/function.php';
echo '<div class="col-md-4 col-md-offset-4">
<div id="title" style="margin: 10px;"></div>
<form class="form-inline" method="get" action="' . $_SERVER['PHP_SELF'] . '" id="form" name="delForm" onSubmit="getStr();">
<div class="form-group">
<label for="exampleInputInviteCode3">删除图片-格式:</label>
<input type="text" class="form-control" id="exampleInputInviteCode3" name="url" placeholder="https://i1.100024.xyz/i/2021/05/04/10fn9ei.jpg">
</div>
<button type="submit" class="btn btn-danger">删除</button>
</form>
</div>
';
if (empty($_REQUEST)) {
echo '
<script>
new $.zui.Messager("没有要删除的图片!", {type: "danger" // 定义颜色主题
}).show();
// 延时3.5s跳转
window.setTimeout("window.location=\'/../ \'",3500);
</script>
';
} elseif (isset($_GET['url'])) {
$img = $_GET['url'];
echo '
<div class="col-md-12">
<hr />
<div style="text-align:center;"><span class="label">图片属性:'.@getimagesize($img)[0].'px X '.@getimagesize($img)[1].'px</span></div>
<a href="' . $img . '" target="_blank"><img src="' . $img . '" alt="简单图床-EasyImage" class="img-thumbnail"></a>
</div>';
}
// 解密删除
if (isset($_GET['hash'])) {
$delHash = $_GET['hash'];
$delHash = urlHash($delHash, 1);
getDel($delHash, 'hash');
}
// 检查登录后再处理url删除请求
if (is_online()) {
if (isset($_GET['url'])) {
getDel($_GET['url'], 'url');
}
} else {
if (isset($_GET['url'])) {
echo '
<script>
new $.zui.Messager("请登录后再删除", {type: "danger" // 定义颜色主题
}).show();
// 延时2s跳转
window.setTimeout("window.location=\'/../libs/login.php \'",2000);
</script>
';
}
}
require_once APP_ROOT . '/libs/footer.php';
?>
<script>
// 修改网页标题
document.title = "删除图片 - <?php echo $config['title']; ?>";
var oBtn = document.getElementById('del');
var oTi = document.getElementById('title');
if ('oninput' in oBtn) {
oBtn.addEventListener("input", getWord, false);
} else {
oBtn.onpropertychange = getWord;
}
function getWord() {
oTi.innerHTML = '<img src="' + oBtn.value + '" width="200" class="img-rounded" /><br />';
}
</script>

121
api/index.php Executable file
View File

@ -0,0 +1,121 @@
<?php
require_once __DIR__ . './../libs/function.php';
require_once APP_ROOT . '/api/libs/apiFunction.php';
require_once APP_ROOT . '/libs/class.upload.php';
require_once APP_ROOT . '/libs/WaterMask.php';
require_once APP_ROOT . '/config/api_key.php';
// 检查是否开启api上传
if ($config['apiStatus']) {
header('Access-Control-Allow-Origin:*');
} else {
exit('API closed');
}
// 检查api合法性
checkToken($_POST['token']);
$token = $_POST['token'];
$handle = new Upload($_FILES['image'], 'zh_CN');
if ($handle->uploaded) {
// 允许上传的mime类型
$handle->allowed = array('image/*');
// 文件命名
$handle->file_new_name_body = imgName() . '_' . getID($token);
// 最大上传限制
$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('../' . config_path());
// 设置水印
if ($config['watermark'] > 0) {
switch ($config['watermark']) {
case 1: // 文字水印 过滤gif
if (isAnimatedGif($handle->file_src_pathname) === 0) {
$arr = [
# 水印图片路径(如果不存在将会被当成是字符串水印)
'res' => $config['waterText'],
# 水印显示位置
'pos' => $config['waterPosition'],
# 不指定name(会覆盖原图也就是保存成thumb.jpeg)
'name' => $handle->file_dst_pathname,
'font' => $config['textFont'],
'fontSize' => $config['textSize'],
'color' => $config['textColor'],
];
Imgs::setWater($handle->file_dst_pathname, $arr);
}
break;
case 2: // 图片水印
if (isAnimatedGif($handle->file_src_pathname) === 0) {
$arr = [
# 水印图片路径(如果不存在将会被当成是字符串水印)
'res' => $config['waterImg'],
# 水印显示位置
'pos' => $config['waterPosition'],
# 不指定name(会覆盖原图也就是保存成thumb.jpeg)
'name' => $handle->file_dst_pathname,
];
Imgs::setWater($handle->file_dst_pathname, $arr);
}
break;
default:
echo $handle->error;
break;
}
}
// 图片完整相对路径:/i/2021/05/03/k88e7p.jpg
if ($handle->processed) {
header('Content-type:text/json');
// 上传成功后返回json数据
$imageUrl = $config['imgurl'] . config_path() . $handle->file_dst_name;
$delUrl = $config['domain'] . '/api/del.php?hash=' . urlHash(config_path() . $handle->file_dst_name, 0);
$reJson = array(
"result" => 'success',
"url" => $imageUrl,
"del" => $delUrl,
);
echo json_encode($reJson);
$handle->clean();
} else {
// 上传错误 返回错误信息
$reJson = array(
"result" => 'failed',
"message" => $handle->error,
);
echo json_encode($reJson, JSON_UNESCAPED_UNICODE);
}
// 压缩图片 后压缩模式,不影响前台输出速度
if (!isAnimatedGif($handle->file_dst_pathname))
if ($config['compress']) {
require '../libs/compress/Imagick/class.Imgcompress.php';
$img = new Imgcompress($handle->file_dst_pathname, 1);
$img->compressImg($handle->file_dst_pathname);
// 释放
ob_flush();
flush();
}
unset($handle);
}

52
api/libs/apiFunction.php Executable file
View File

@ -0,0 +1,52 @@
<?php
require_once './../config/api_key.php';
require_once './../config/config.php';
// Token 生成
function privateToken($length = 32)
{
$output = '';
for ($a = 0; $a < $length; $a++) {
$output .= chr(mt_rand(65, 122)); //生成php随机数
}
return md5($output);
}
// 检查Token
function checkToken($token)
{
global $tokenList;
$token = preg_replace('/[\W]/', '', $token); // 过滤非字母数字,删除空格
if (in_array($token, $tokenList)) {
return True;
} else {
exit('此Token不存在' . $token);
}
}
// 通过Token查找用户ID
function getID($token)
{
global $tokenList;
$token = preg_replace('/[\W]/', '', $token); // 过滤非字母数字,删除空格
$key = array_search($token, $tokenList);
if ($key >= 0) {
return $key;
} else {
return ('没有这个用户ID');
}
};
// 通过ID查找用户Token
function getIDToken($id)
{
global $tokenList;
$id = preg_replace('/[\W]/', '', $id); // 过滤非字母数字,删除空格
foreach ($tokenList as $key => $value) {
if ($key == $id) {
return $value;
}
}
};

BIN
favicon.ico Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

4
robots.txt Executable file
View File

@ -0,0 +1,4 @@
# robots.txt
User-agent: *
Disallow:
Disallow: /config/