Skip to content

Commit 1fcf702

Browse files
committed
v2.3
1 parent d3fa04b commit 1fcf702

23 files changed

+303
-29
lines changed

application/config/routes.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,7 @@
5555
//API路由
5656
$route['api/upload'] = 'upload/localhost';
5757
$route['api/upload/parse'] = 'upload/parse';
58-
$route['api/upload/(:any)'] = 'upload/localhost/$1';
58+
$route['api/upload/(:any)'] = 'upload/localhost/$1';
59+
$route['api/parse'] = '/upload/parse';
60+
//删除链接
61+
$route['delete/(:any)'] = '/del/token/$1';

application/controllers/Del.php

+40-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?php
2-
// 该控制器删除图片
2+
/**
3+
* ImgURL删除图片类
4+
*
5+
* @package upgrade
6+
* @author xiaoz
7+
* @link https://imgurl.org/
8+
*/
39
defined('BASEPATH') OR exit('No direct script access allowed');
410
class Del extends CI_Controller{
511
//构造函数
@@ -8,14 +14,16 @@ public function __construct(){
814

915
//加载模型
1016
$this->load->model('query','',TRUE);
17+
//加载数据库模型
18+
$this->load->model('delete','',TRUE);
1119
//加载类
1220
$this->load->library('basic');
13-
//检测是否登录
14-
$this->basic->is_login(TRUE);
15-
1621
}
17-
//根据img_images ID删除图片
22+
//根据img_images ID删除图片,需要检查用户是否登录
1823
public function id($id){
24+
//检测是否登录
25+
$this->basic->is_login(TRUE);
26+
1927
@$id = (int)$id;
2028

2129
$img = $this->query->img_id($id);
@@ -38,5 +46,32 @@ public function id($id){
3846
$re = json_encode($re);
3947
echo $re;
4048
}
49+
//根据token删除单张图片,不需要登录,只需要知道token即可
50+
public function token($value){
51+
//对value进行过滤
52+
$value = trim($value);
53+
$value = strip_tags($value);
54+
$len = strlen($value);
55+
if($len !== 16){
56+
exit('不是有效的token!');
57+
}
58+
//获取图片信息
59+
$img = $this->query->get_token($value);
60+
//如果返回空,说明token不存在
61+
if($img === NULL){
62+
exit('token不存在,可能是图片已经被删除!');
63+
}
64+
//删除图片
65+
//从数据库中删除
66+
$this->delete->del_img($img->imgid);
67+
//从磁盘中删除
68+
$path = FCPATH.$img->path;
69+
$thumbnail_path = FCPATH.$img->thumb_path;
70+
//缩略图地址
71+
unlink($path);
72+
unlink($thumbnail_path);
73+
74+
echo '图片已删除!';
75+
}
4176
}
4277
?>

application/controllers/Maintain.php

+9
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ public function import($id){
5858
// $query = $this->db->query($sql)->row();
5959
// var_dump($query);
6060
}
61+
//版本升级
62+
public function upgrade(){
63+
$data['admin_title'] = 'ImgURL升级';
64+
//加载视图
65+
$this->load->view('admin/header',$data);
66+
$this->load->view('admin/left');
67+
$this->load->view('admin/upgrade');
68+
$this->load->view('admin/footer');
69+
}
6170

6271
}
6372
?>

application/controllers/Upgrade.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* ImgURL升级类
4+
*
5+
* @package upgrade
6+
* @author xiaoz
7+
* @link https://imgurl.org/
8+
*/
9+
10+
defined('BASEPATH') OR exit('No direct script access allowed');
11+
class Upgrade extends CI_Controller{
12+
//构造函数
13+
public function __construct(){
14+
parent::__construct();
15+
16+
//加载辅助类
17+
$this->load->library('basic');
18+
$this->basic->is_login(TRUE);
19+
//加载模型
20+
$this->load->model('query','',TRUE);
21+
}
22+
public function v22_to_v23(){
23+
//升级数据库操作
24+
$result = $this->query->to23();
25+
if($result){
26+
echo '升级完毕,请关闭此页面!';
27+
}
28+
else{
29+
echo '升级失败,未知错误!';
30+
}
31+
}
32+
}

application/controllers/Upload.php

+36-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class Upload extends CI_Controller{
2121
public $temp;
2222
//用户是否已经登录的属性
2323
protected $user;
24+
//获取站点主域名
25+
protected $main_domain;
2426
//构造函数
2527
public function __construct()
2628
{
@@ -44,6 +46,8 @@ public function __construct()
4446
$this->load->library('basic');
4547
//加载查询模型
4648
$this->load->model('query','',TRUE);
49+
$this->main_domain = $this->basic->domain();
50+
4751
//用户已经登录
4852
if($this->basic->is_login(FALSE)){
4953
$this->user = 'admin';
@@ -155,7 +159,17 @@ public function localhost($type = 'json'){
155159
}
156160
//图片没有上传过
157161
else{
158-
//需要插入到images表的数据
162+
$arr = array(
163+
"ip" => get_ip(),
164+
"ua" => get_ua(),
165+
"date" => $this->date
166+
);
167+
168+
//生成token
169+
$token = $this->token($arr);
170+
//生成删除链接
171+
$delete = $this->main_domain.'/delete/'.$token;
172+
//需要插入到img_images表的数据
159173
$datas = array(
160174
"imgid" => $imgid,
161175
"path" => $relative_path,
@@ -165,7 +179,8 @@ public function localhost($type = 'json'){
165179
"ua" => get_ua(),
166180
"date" => $this->date,
167181
"user" => $this->user,
168-
"level" => 'unknown'
182+
"level" => 'unknown',
183+
"token" => $token
169184
);
170185
//需要插入到imginfo表的数据
171186
$imginfo = array(
@@ -189,7 +204,8 @@ public function localhost($type = 'json'){
189204
"url" => $url,
190205
"thumbnail_url" => $thumbnail_url,
191206
"width" => $data['image_width'],
192-
"height" => $data['image_height']
207+
"height" => $data['image_height'],
208+
"delete" => $delete
193209
);
194210
//根据不同的类型返回不同的数据
195211
$this->re_data($type,$info);
@@ -442,5 +458,22 @@ public function parse(){
442458
$this->succeed_msg($info);
443459
//echo $re;
444460
}
461+
/*
462+
1. 该方法生成图片的唯一删除token
463+
2. 参数为一个数组,内容为IP/UA/DATE
464+
3. ip + ua + date + 4位随机数,进行md5加密得到token
465+
*/
466+
protected function token($arr){
467+
$ip = $arr['ip'];
468+
$ua = $arr['ua'];
469+
$date = $arr['date'];
470+
//生成4位随机数
471+
$str = GetRandStr(4);
472+
$token = $ip.$ua.$date.$str;
473+
$token = md5($token);
474+
//token只需要16位
475+
$token = substr($token, 8, 16);
476+
return $token;
477+
}
445478
}
446479
?>

application/helpers/basic_helper.php

+20
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,24 @@ function thumbnail($img){
141141
return $img['path'];
142142
}
143143
}
144+
//生成4位随机数,方法来自:https://blog.csdn.net/happy_jijiawei/article/details/50581094
145+
function GetRandStr($len)
146+
{
147+
$chars = array(
148+
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
149+
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
150+
"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
151+
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
152+
"S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
153+
"3", "4", "5", "6", "7", "8", "9"
154+
);
155+
$charsLen = count($chars) - 1;
156+
shuffle($chars);
157+
$output = "";
158+
for ($i=0; $i<$len; $i++)
159+
{
160+
$output .= $chars[mt_rand(0, $charsLen)];
161+
}
162+
return $output;
163+
}
144164
?>

application/libraries/Basic.php

+5
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,10 @@ public function conf($arg = ''){
134134
break;
135135
}
136136
}
137+
//获取站点主域名
138+
public function domain(){
139+
$domain = $this->CI->query->get_domain();
140+
return $domain;
141+
}
137142
}
138143
?>

application/models/Query.php

+41
Original file line numberDiff line numberDiff line change
@@ -323,5 +323,46 @@ public function found_img($type,$page){
323323
$datas = $this->db->query($sql)->result_array();
324324
return $datas;
325325
}
326+
//v2.2升级v2.3
327+
public function to23(){
328+
// $sql = 'alter table "img_images" ADD "token" TEXT(16) DEFAULT NULL;
329+
// CREATE UNIQUE INDEX "token" ON "img_images" ("token" ASC);
330+
// ';
331+
$sqls = array(
332+
'alter table "img_images" ADD "token" TEXT(16) DEFAULT NULL;',
333+
'CREATE UNIQUE INDEX "token" ON "img_images" ("token" ASC)',
334+
'CREATE UNIQUE INDEX "imginfo_imgid" ON "img_imginfo" ("imgid" ASC)'
335+
);
336+
//遍历SQL语句
337+
foreach ($sqls as $value) {
338+
$datas = $this->db->query($value);
339+
}
340+
//var_dump($datas);
341+
if($datas){
342+
return TRUE;
343+
}
344+
else{
345+
return FALSE;
346+
}
347+
}
348+
//查询站点主域名
349+
public function get_domain() {
350+
$sql = 'SELECT "values" FROM "img_options" WHERE `name` = "site_url"';
351+
$data = $this->db->query($sql)->row();
352+
353+
if($data){
354+
return $data->values;
355+
}
356+
else{
357+
return FALSE;
358+
}
359+
}
360+
//根据token查询图片信息
361+
public function get_token($value){
362+
//先获取img id
363+
$sql = "SELECT a.*,b.mime,b.width,b.height,b.views,b.ext,b.client_name FROM img_images AS a INNER JOIN img_imginfo AS b ON a.token = '{$value}' AND a.imgid = b.imgid";
364+
$imginfo = $this->db->query($sql)->row();
365+
return $imginfo;
366+
}
326367
}
327368
?>

application/views/admin/header.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<title><?php echo $admin_title; ?> - ImgURL后台管理</title>
1414
<link rel="stylesheet" href="/static/layui/css/layui.css">
1515
<link rel="stylesheet" href="/static/font-awesome/css/font-awesome.min.css">
16-
<link rel="stylesheet" href="/static/css/admin.css?v=<?php echo $version; ?>">
16+
<link rel="stylesheet" href="/static/css/admin.css?v=<?php echo $version; ?>">
1717
<script src = "/static/js/jquery.min.js"></script>
1818
</head>
1919
<body class="layui-layout-body">

application/views/admin/images.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,15 @@
140140
<div class="layui-col-lg6" id = "paging">
141141
<?php echo $page; ?>
142142
</div>
143-
<div class="layui-col-lg6">
143+
<div class="layui-col-lg3">
144+
<span>操作:</span>
145+
<div class="layui-btn-group">
146+
<button type="button" class="layui-btn layui-btn-xs" onclick = "check_all()">全选</button>
147+
<button type="button" class="layui-btn layui-btn-xs" onclick = "cancel_all()">取消全选</button>
148+
<!--<button type="button" class="layui-btn layui-btn-xs" onclick = "invert_selection()">反选</button>-->
149+
</div>
150+
</div>
151+
<div class="layui-col-lg3">
144152
<!-- <button class="layui-btn layui-btn-xs" id = "checkAll">全选</button>--> <label>选中项:</label><button class="layui-btn layui-btn-xs layui-btn-danger" onclick = "del_more()">删除</button>
145153
</div>
146154
</div>

application/views/admin/index.php

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<script src="/static/js/Chart.min.js"></script>
12
<div class="layui-container" style = "margin-top:2em;">
23
<div class="layui-row layui-col-space20">
34
<div class="layui-col-lg3">

application/views/admin/left.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
<li class="layui-nav-item">
3535
<a href="javascript:;"><i class="layui-icon layui-icon-app"></i> 管理维护</a>
3636
<dl class="layui-nav-child">
37-
<dd><a href="javascript:;" onclick = "version()">当前版本</a></dd>
38-
<dd><a href="/maintain/upto2">1.x升级2.x</a></dd>
37+
<dd><a href="javascript:;" onclick = "version()">当前版本</a></dd>
38+
<dd><a href="/maintain/upto2">1.x升级2.x</a></dd>
39+
<dd><a href="/maintain/upgrade">版本升级</a></dd>
3940
<!-- <dd><a href="/maintain/upto2">检查更新</a></dd> -->
4041
<!-- <dd><a href="javascript:;">FTP</a></dd> -->
4142
<!-- <dd><a href="">七牛云</a></dd>

application/views/admin/upgrade.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
//读取版本号
3+
$content = file_get_contents(FCPATH."/data/version.txt");
4+
$content = explode("-",$content);
5+
$version = $content[0];
6+
?>
7+
<div class="layui-container" style = "margin-top:2em;">
8+
<div class="layui-row">
9+
<div class="layui-col-lg12">
10+
<div>
11+
<ol>
12+
<li>1. 您当前使用的版本为<code style = "color:red;"><?php echo $version; ?></code></li>
13+
<li>2. 升级之前请备份数据,升级之前请备份数据,升级之前请备份数据</li>
14+
<li>3. 不要跨版本升级</li>
15+
<li>4. 上述准备完成后,点击下方对应的版本进行升级</li>
16+
<li>4. 没事不要乱点,否则后果自负</li>
17+
</ol>
18+
</div>
19+
<div style = "margin-top:1em;"><a href="/upgrade/v22_to_v23" class="layui-btn" target = "_blank">v2.2 > v2.3</a></div>
20+
</div>
21+
</div>
22+
</div>

application/views/user/footer.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
<div class = "footer">
1111
<div class = "layui-container">
1212
<div class = "layui-row">
13+
<!--未经作者授权,请勿去掉版权,谢谢-->
1314
<div class = "layui-col-lg12">
14-
Copyright © 2017-2019 Powered by <a href="https://imgurl.org/" target = "_blank">ImgURL</a> | Author <a href="https://www.xiaoz.me/" target = "_blank">xiaoz.me</a> |
15+
Copyright © 2017-2019 Powered by <a href="https://imgurl.org/" target = "_blank" title = "ImgURL是一个开源免费的图床程序">ImgURL</a> | Author <a href="https://www.xiaoz.me/" target = "_blank" title = "小z博客">xiaoz.me</a> |
1516
<!-- 简单判断用户是否登录 -->
1617
<?php if((isset($_COOKIE['user'])) && (isset($_COOKIE['token']))){ ?>
1718
<a href="/user/logout">logout</a>

application/views/user/header.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@
4545
<li class="layui-nav-item"><a href="/home/multiple"><i class="layui-icon layui-icon-upload"></i> 多图上传</a></li>
4646
<li class="layui-nav-item"><a href="/found"><i class="layui-icon layui-icon-search"></i> 探索发现</a></li>
4747
<li class="layui-nav-item"><a href="/home/log"><i class="layui-icon layui-icon-notice"></i> 更新日志</a></li>
48-
<li class="layui-nav-item"><a href="https://doc.xiaoz.me/#/imgurl2/api" target = "_blank"><i class="layui-icon layui-icon-template-1"></i> API</a></li>
49-
<li class="layui-nav-item"><a href="https://doc.xiaoz.me/#/imgurl2/" target = "_blank" rel = "nofollow"><i class="layui-icon">&#xe705;</i> 帮助文档</a></li>
48+
<li class="layui-nav-item">
49+
<a href="https://dwz.ovh/imgurldoc" target = "_blank" rel = "nofollow"><i class="layui-icon">&#xe705;</i> 帮助文档</a>
50+
<dl class="layui-nav-child"> <!-- 二级菜单 -->
51+
<dd><a href="https://www.xiaoz.me/doc/doc-imgurl/install" rel = "nofollow" target = "_blank">安装ImgURL</a></dd>
52+
<dd><a href="https://www.xiaoz.me/doc/doc-imgurl/api" rel = "nofollow" target = "_blank">ImgURL API</a></dd>
53+
</dl>
54+
</li>
5055
<li class="layui-nav-item"><a href="https://github.com/helloxz/imgurl" target = "_blank" rel = "nofollow"><i class="layui-icon">&#xe635;</i> 源码</a></li>
5156
<li class="layui-nav-item"><a href="/page/use"><i class="layui-icon">&#xe60b;</i> 关于</a></li>
5257
<!-- 简单判断用户是否登录 -->

0 commit comments

Comments
 (0)