- 优化二级目录使用
parent
9f512bcf2d
commit
0f89648b76
|
@ -124,7 +124,7 @@ if (isset($_POST['password']) and isset($_POST['user'])) {
|
||||||
<img src="<?php echo $config['login_bg']; ?>" alt="简单图床登陆界面背景图" />
|
<img src="<?php echo $config['login_bg']; ?>" alt="简单图床登陆界面背景图" />
|
||||||
</div>
|
</div>
|
||||||
<div class="formBx">
|
<div class="formBx">
|
||||||
<form class="form-horizontal" action="/admin/index.php" method="post" onsubmit="return md5_post()">
|
<form class="form-horizontal" action="index.php" method="post" onsubmit="return md5_post()">
|
||||||
<h2>登录</h2>
|
<h2>登录</h2>
|
||||||
<label for="account" class="col-sm-2"></label>
|
<label for="account" class="col-sm-2"></label>
|
||||||
<input type="text" name="user" id="account" class="form-control" value="" placeholder="输入登录账号" autocomplete="off" required="required">
|
<input type="text" name="user" id="account" class="form-control" value="" placeholder="输入登录账号" autocomplete="off" required="required">
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Verot\Upload;
|
namespace Verot\Upload;
|
||||||
|
|
||||||
require_once __DIR__ . '/../app/function.php';
|
require_once __DIR__ . '/../app/function.php';
|
||||||
|
|
|
@ -1,36 +1,50 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 图床公共信息查询APi
|
* 图床公共信息查询API
|
||||||
* 2022年2月22日11:41:38
|
* 2024年04月07日 08:00:00
|
||||||
* @author Icret
|
* @author Icret
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// 定义常量以替换魔术字符串
|
||||||
|
const TIME_KEY = 'total_time';
|
||||||
|
const TODAY_UPLOAD_KEY = 'todayUpload';
|
||||||
|
const YESTERDAY_UPLOAD_KEY = 'yestUpload';
|
||||||
|
const USAGE_SPACE_KEY = 'usage_space';
|
||||||
|
const FILENUM_KEY = 'filenum';
|
||||||
|
const DIRNUM_KEY = 'dirnum';
|
||||||
|
|
||||||
require_once '../app/chart.php';
|
require_once '../app/chart.php';
|
||||||
|
|
||||||
// 检查是否开启查询
|
// 检查是否开启查询
|
||||||
if ($config['public'] === 0) die('开放数据接口已关闭!');
|
if ($config['public'] === 0) {
|
||||||
|
http_response_code(403); // 返回403 Forbidden
|
||||||
|
die('开放数据接口已关闭!');
|
||||||
|
}
|
||||||
|
|
||||||
// 获得get值
|
// 获取并验证GET参数
|
||||||
$show = (empty($_GET['show'])) ? die('没有参数!') : htmlspecialchars($_GET['show']);
|
$show = isset($_GET['show']) ? trim($_GET['show']) : '';
|
||||||
|
if (!$show || !in_array($show, $config['public_list'])) {
|
||||||
// 检查是否在允许范围内
|
http_response_code(400); // 返回400 Bad Request
|
||||||
if (!in_array($show, $config['public_list'])) die('没有权限或参数错误!');
|
die('没有权限或参数错误!');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
// 根据请求返回值
|
// 根据请求返回值
|
||||||
switch ($show) {
|
switch ($show) {
|
||||||
// 统计时间
|
// 统计时间
|
||||||
case 'time':
|
case 'time':
|
||||||
echo read_total_json('total_time');
|
echo read_total_json(TIME_KEY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 今日上传
|
// 今日上传
|
||||||
case 'today':
|
case 'today':
|
||||||
echo read_total_json('todayUpload');
|
echo read_total_json(TODAY_UPLOAD_KEY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 昨日上传
|
// 昨日上传
|
||||||
case 'yesterday':
|
case 'yesterday':
|
||||||
echo read_total_json('yestUpload');
|
echo read_total_json(YESTERDAY_UPLOAD_KEY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 总空间
|
// 总空间
|
||||||
|
@ -40,34 +54,61 @@ switch ($show) {
|
||||||
|
|
||||||
// 已用空间
|
// 已用空间
|
||||||
case 'used_space':
|
case 'used_space':
|
||||||
echo getDistUsed(disk_total_space('.') - disk_free_space('.'));
|
$totalSpace = disk_total_space('.');
|
||||||
|
if ($totalSpace !== false && is_numeric($totalSpace)) {
|
||||||
|
$freeSpace = disk_free_space('.');
|
||||||
|
if ($freeSpace !== false && is_numeric($freeSpace)) {
|
||||||
|
echo getDistUsed($totalSpace - $freeSpace);
|
||||||
|
} else {
|
||||||
|
throw new Exception('无法获取磁盘剩余空间');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Exception('无法获取磁盘总空间');
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 剩余空间
|
// 剩余空间
|
||||||
case 'free_space':
|
case 'free_space':
|
||||||
echo getDistUsed(disk_free_space('/'));
|
$freeSpace = disk_free_space('/');
|
||||||
|
if ($freeSpace !== false && is_numeric($freeSpace)) {
|
||||||
|
echo getDistUsed($freeSpace);
|
||||||
|
} else {
|
||||||
|
throw new Exception('无法获取磁盘剩余空间');
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 图床使用空间
|
// 图床使用空间
|
||||||
case 'image_used':
|
case 'image_used':
|
||||||
echo read_total_json('usage_space');
|
echo read_total_json(USAGE_SPACE_KEY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 文件数量
|
// 文件数量
|
||||||
case 'file':
|
case 'file':
|
||||||
echo read_total_json('filenum');
|
echo read_total_json(FILENUM_KEY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 文件夹数量
|
// 文件夹数量
|
||||||
case 'dir':
|
case 'dir':
|
||||||
echo read_total_json('dirnum');
|
echo read_total_json(DIRNUM_KEY);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// 修复"month"分支的逻辑
|
||||||
case 'month':
|
case 'month':
|
||||||
foreach (read_chart_total()['number'] as $value)
|
$chartTotal = read_chart_total();
|
||||||
|
if (isset($chartTotal['number']) && is_array($chartTotal['number'])) {
|
||||||
|
foreach ($chartTotal['number'] as $value) {
|
||||||
echo $value;
|
echo $value;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Exception('无法获取图表总数中的“number”数据');
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return read_chart_total();
|
echo read_chart_total();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
http_response_code(500); // 返回500 Internal Server Error
|
||||||
|
die("发生错误: " . $e->getMessage());
|
||||||
|
}
|
|
@ -24,7 +24,7 @@
|
||||||
// 设置html为utf8
|
// 设置html为utf8
|
||||||
header('Content-Type:text/html;charset=utf-8');
|
header('Content-Type:text/html;charset=utf-8');
|
||||||
// 定义根目录
|
// 定义根目录
|
||||||
define('APP_ROOT', str_replace('\\', '/', realpath(dirname(__FILE__) . '/../')));
|
define('APP_ROOT', str_replace(DIRECTORY_SEPARATOR, '/', realpath(dirname(__FILE__) . '/../')));
|
||||||
// 时区设置 https://www.php.net/manual/zh/timezones.php
|
// 时区设置 https://www.php.net/manual/zh/timezones.php
|
||||||
require_once APP_ROOT . '/config/config.php';
|
require_once APP_ROOT . '/config/config.php';
|
||||||
empty($config['timezone']) ? date_default_timezone_set('Asia/Shanghai') : date_default_timezone_set($config['timezone']);
|
empty($config['timezone']) ? date_default_timezone_set('Asia/Shanghai') : date_default_timezone_set($config['timezone']);
|
||||||
|
|
|
@ -586,7 +586,7 @@ function getDel($url, $type)
|
||||||
$url = urldecode(trim($url));
|
$url = urldecode(trim($url));
|
||||||
|
|
||||||
if ($type == 'url') {
|
if ($type == 'url') {
|
||||||
$url = $_SERVER['DOCUMENT_ROOT'] . $url;
|
$url = APP_ROOT . $url;
|
||||||
}
|
}
|
||||||
if ($type == 'hash') {
|
if ($type == 'hash') {
|
||||||
$url = APP_ROOT . $url;
|
$url = APP_ROOT . $url;
|
||||||
|
@ -643,7 +643,7 @@ function easyimage_delete($url, $type)
|
||||||
$url = urldecode(trim($url));
|
$url = urldecode(trim($url));
|
||||||
|
|
||||||
if ($type == 'url') {
|
if ($type == 'url') {
|
||||||
$url = $_SERVER['DOCUMENT_ROOT'] . $url;
|
$url = APP_ROOT . $url;
|
||||||
}
|
}
|
||||||
if ($type == 'hash') {
|
if ($type == 'hash') {
|
||||||
$url = APP_ROOT . $url;
|
$url = APP_ROOT . $url;
|
||||||
|
|
|
@ -68,7 +68,7 @@ class Ip2Region
|
||||||
$geo = $this->memorySearch($ip);
|
$geo = $this->memorySearch($ip);
|
||||||
$arr = explode('|', str_replace(['0|'], '|', isset($geo['region']) ? $geo['region'] : ''));
|
$arr = explode('|', str_replace(['0|'], '|', isset($geo['region']) ? $geo['region'] : ''));
|
||||||
if (($last = array_pop($arr)) === '内网IP') $last = '';
|
if (($last = array_pop($arr)) === '内网IP') $last = '';
|
||||||
return join('', $arr) . (empty($last) ? '' : "[{$last}]");
|
return join('', $arr) . (empty($last) ? '' : "【{$last}】");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -126,7 +126,7 @@ class XdbSearcher
|
||||||
// read the vector index block
|
// read the vector index block
|
||||||
$buff = $this->read(self::HeaderInfoLength + $idx, 8);
|
$buff = $this->read(self::HeaderInfoLength + $idx, 8);
|
||||||
if ($buff === null) {
|
if ($buff === null) {
|
||||||
throw new Exception("failed to read vector index at ${idx}");
|
throw new Exception("failed to read vector index at {$idx}");
|
||||||
}
|
}
|
||||||
|
|
||||||
$sPtr = self::getLong($buff, 0);
|
$sPtr = self::getLong($buff, 0);
|
||||||
|
@ -147,7 +147,7 @@ class XdbSearcher
|
||||||
// read the segment index
|
// read the segment index
|
||||||
$buff = $this->read($p, self::SegmentIndexSize);
|
$buff = $this->read($p, self::SegmentIndexSize);
|
||||||
if ($buff == null) {
|
if ($buff == null) {
|
||||||
throw new Exception("failed to read segment index at ${p}");
|
throw new Exception("failed to read segment index at {$p}");
|
||||||
}
|
}
|
||||||
|
|
||||||
$sip = self::getLong($buff, 0);
|
$sip = self::getLong($buff, 0);
|
||||||
|
|
Binary file not shown.
|
@ -32,7 +32,7 @@ Thumb::show($src, $w, $h);
|
||||||
*
|
*
|
||||||
* TimThumb参数指南
|
* TimThumb参数指南
|
||||||
* 命令 作用 参数 描述
|
* 命令 作用 参数 描述
|
||||||
* src 源 图像URL 告诉TimThumb调整哪个图片
|
* src 源文件 图像URL 告诉TimThumb调整哪个图片
|
||||||
* w 宽度 宽度调整 调整输出图像的宽度
|
* w 宽度 宽度调整 调整输出图像的宽度
|
||||||
* h 高度 高度调整 调整输出图像的高度
|
* h 高度 高度调整 调整输出图像的高度
|
||||||
* q 质量 0-100 压缩质量,值越大质量越高。不建议高于95
|
* q 质量 0-100 压缩质量,值越大质量越高。不建议高于95
|
||||||
|
@ -40,8 +40,8 @@ Thumb::show($src, $w, $h);
|
||||||
* zc 缩放/裁剪 0、1、2、3 0: 根据传入的值进行缩放(不裁剪), 1:以最合适的比例裁剪和调整大小(裁剪), 2:按比例调整大小,并添加边框(裁剪),3:按比例调整大小,不添加边框(裁剪)
|
* zc 缩放/裁剪 0、1、2、3 0: 根据传入的值进行缩放(不裁剪), 1:以最合适的比例裁剪和调整大小(裁剪), 2:按比例调整大小,并添加边框(裁剪),3:按比例调整大小,不添加边框(裁剪)
|
||||||
* f 过滤器 太多了 可以改变亮度/对比度;甚至模糊图像
|
* f 过滤器 太多了 可以改变亮度/对比度;甚至模糊图像
|
||||||
* s 锐化 锐化 使得按比例缩小图片看起来有点;更清晰
|
* s 锐化 锐化 使得按比例缩小图片看起来有点;更清晰
|
||||||
* cc 画布上的颜色 十六进制的颜色值(# ffffff) 改变背景颜色。 大多数更改缩放和作物设置时使用,进而可以添加图像边界。
|
* cc 画布颜色 #ffffff 改变背景颜色。 大多数更改缩放和作物设置时使用,进而可以添加图像边界。
|
||||||
* ct 画布的透明度 true (1) 使用透明而忽略背景颜色
|
* ct 画布透明度 true (1) 使用透明而忽略背景颜色
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once __DIR__ . '/function.php';
|
require_once __DIR__ . '/function.php';
|
||||||
|
@ -74,7 +74,6 @@ $ALLOWED_SITES = array(
|
||||||
$config['imgurl'],
|
$config['imgurl'],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修复无法生成生成webp动态图片的缩略图bug
|
* 修复无法生成生成webp动态图片的缩略图bug
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -42,7 +42,6 @@ try {
|
||||||
throw new Exception('<div class="alert alert-info">没有上传日志!<div>');
|
throw new Exception('<div class="alert alert-info">没有上传日志!<div>');
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
echo $e->getMessage();
|
|
||||||
require_once APP_ROOT . '/app/footer.php';
|
require_once APP_ROOT . '/app/footer.php';
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
107
docs/API.md
107
docs/API.md
|
@ -1,67 +1,94 @@
|
||||||
返回状态可以参考 [常见状态代码](./常见状态代码.md)
|
### 上传成功后返回JSON示例
|
||||||
- 上传成功后返回JSON
|
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"result":"success","code":200,
|
"result":"success",
|
||||||
|
"code":200,
|
||||||
"url":"https:\/\/i2.100024.xyz\/2023\/01\/24\/10gwv0y-0.webp",
|
"url":"https:\/\/i2.100024.xyz\/2023\/01\/24\/10gwv0y-0.webp",
|
||||||
"srcName":"195124",
|
"srcName":"195124",
|
||||||
"thumb":"https:\/\/png.cm\/application\/thumb.php?img=\/i\/2023\/01\/24\/10gwv0y-0.webp",
|
"thumb":"https:\/\/png.cm\/application\/thumb.php?img=\/i\/2023\/01\/24\/10gwv0y-0.webp",
|
||||||
"del":"https:\/\/png.cm\/application\/del.php?hash=bW8vWG4vcG8yM2pLQzRJUGI0dHlTZkN4L2grVmtwUTFhd1A4czJsbHlMST0="
|
"del":"https:\/\/png.cm\/application\/del.php?hash=bW8vWG4vcG8yM2pLQzRJUGI0dHlTZkN4L2grVmtwUTFhd1A4czJsbHlMST0="
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
- 返回示例解释
|
||||||
|
`result` 返回状态
|
||||||
|
`code` 返回状态编号 参考[常见状态代码](./常见状态代码.md)
|
||||||
|
`url` 文件链接
|
||||||
|
`srcName` 原始名称
|
||||||
|
`thumb` 缩略图
|
||||||
|
`del` 文件删除链接
|
||||||
|
|
||||||
- html示例
|
### 上传示例 仅供参考
|
||||||
|
|
||||||
|
- html
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<form action="http://127.0.0.1/api/index.php" method="post" enctype="multipart/form-data">
|
<form action="http://127.0.0.1/api/index.php" method="post" enctype="multipart/form-data">
|
||||||
<input type="file" name="image" accept="image/*">
|
<input type="file" name="image" accept="image/*" required>
|
||||||
<input type="text" name="token" placeholder="在tokenList文件找到token并输入" /> <input type="submit" />
|
<input type="text" name="token" placeholder="在tokenList文件找到token并输入" required>
|
||||||
|
<input type="submit" value="上传">
|
||||||
</form>
|
</form>
|
||||||
```
|
|
||||||
- Python示例
|
|
||||||
|
|
||||||
```python
|
```
|
||||||
|
- Python
|
||||||
|
|
||||||
|
```Python
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
url = "https://png.cm/api/index.php"
|
# 本地图片文件路径
|
||||||
|
image_path = "/path/to/your/image.jpg"
|
||||||
|
|
||||||
payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"token\"\r\n\r\n8337effca0ddfcd9c5899f3509b23657\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"image\"\r\n\r\n195124.jpg\r\n-----011000010111000001101001--\r\n\r\n"
|
# token值,需从实际来源获取(例如读取tokenList文件)
|
||||||
headers = {"content-type": "multipart/form-data; boundary=---011000010111000001101001"}
|
token = "your_token_value_here"
|
||||||
|
|
||||||
response = requests.request("POST", url, data=payload, headers=headers)
|
# 目标URL
|
||||||
|
url = "http://127.0.0.1/api/index.php"
|
||||||
|
|
||||||
print(response.text)
|
# 构建请求参数
|
||||||
|
files = {'image': open(image_path, 'rb')}
|
||||||
|
data = {'token': token}
|
||||||
|
|
||||||
|
# 发送POST请求
|
||||||
|
response = requests.post(url, files=files, data=data)
|
||||||
|
|
||||||
|
# 检查响应状态码
|
||||||
|
if response.status_code == 200:
|
||||||
|
print("Upload successful.")
|
||||||
|
else:
|
||||||
|
print(f"Upload failed with status code {response.status_code}.")
|
||||||
```
|
```
|
||||||
- curl示例
|
- Curl
|
||||||
|
|
||||||
```curl
|
```CURL
|
||||||
curl --request POST \
|
curl -X POST http://127.0.0.1/api/index.php \
|
||||||
--url https://png.cm/api/index.php \
|
-F "image=@/path/to/your/file/example.jpg" \
|
||||||
--header 'content-type: multipart/form-data' \
|
-F "token=your_token"
|
||||||
--form token=8337effca0ddfcd9c5899f3509b23657 \
|
|
||||||
--form image=@195124.jpg
|
|
||||||
```
|
```
|
||||||
- JQuery示例
|
|
||||||
|
|
||||||
```jQuery
|
- JQuery
|
||||||
const form = new FormData();
|
|
||||||
form.append("token", "8337effca0ddfcd9c5899f3509b23657");
|
|
||||||
form.append("image", "195124.jpg");
|
|
||||||
|
|
||||||
const settings = {
|
```JAVASCRIPT
|
||||||
"async": true,
|
// 获取文件和token
|
||||||
"crossDomain": true,
|
var file = document.querySelector('input[type="file"]').files[0];
|
||||||
"url": "https://png.cm/api/index.php",
|
var token = $('input[name="token"]').val();
|
||||||
"method": "POST",
|
|
||||||
"headers": {},
|
|
||||||
"processData": false,
|
|
||||||
"contentType": false,
|
|
||||||
"mimeType": "multipart/form-data",
|
|
||||||
"data": form
|
|
||||||
};
|
|
||||||
|
|
||||||
$.ajax(settings).done(function (response) {
|
// 创建FormData对象
|
||||||
console.log(response);
|
var formData = new FormData();
|
||||||
|
formData.append('image', file);
|
||||||
|
formData.append('token', token);
|
||||||
|
|
||||||
|
// 发起上传请求
|
||||||
|
$.ajax({
|
||||||
|
url: 'http://127.0.0.1/api/index.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: formData,
|
||||||
|
processData: false,
|
||||||
|
contentType: false,
|
||||||
|
success: function(response) {
|
||||||
|
console.log('文件上传成功');
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
console.error('文件上传失败: ' + error);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
* 2024-03-04 v2.8.5
|
* 2024-04-08 v2.8.5
|
||||||
- 返回状态统一
|
- 优化API示例
|
||||||
|
- 优化二级目录使用
|
||||||
|
- 修复对PHP8.2支持
|
||||||
|
- 上传返回状态统一
|
||||||
- 增加返回状态文档解释
|
- 增加返回状态文档解释
|
||||||
- 增加通过文件md5禁止上传
|
- 增加通过文件md5禁止上传
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue