From 3df736df371386edccb762f836b8a28d00de5611 Mon Sep 17 00:00:00 2001 From: "wmgang@qq.com" Date: Wed, 23 Nov 2022 15:00:33 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E6=94=B9=E9=BB=98=E8=AE=A4=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E4=BD=8D=E7=BD=AE=202.=E6=B7=BB=E5=8A=A0=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=E6=97=B6=E5=8F=AF=E4=B8=8A=E4=BC=A0=E5=9B=BE=E6=A0=87?= =?UTF-8?q?=E6=88=96=E6=89=8B=E5=B7=A5=E8=BE=93=E5=85=A5=E5=9B=BE=E6=A0=87?= =?UTF-8?q?=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/Api.php | 44 ++++++++++++++++++++++++-- controller/api.php | 13 ++++++-- controller/click.php | 2 +- templates/admin/add_link.php | 14 ++++++++ templates/admin/static/embed.js | 23 +++++++++++++- {static/images => upload}/default.png | Bin 6 files changed, 90 insertions(+), 6 deletions(-) rename {static/images => upload}/default.png (100%) diff --git a/class/Api.php b/class/Api.php index 02dfb4a..833c15d 100755 --- a/class/Api.php +++ b/class/Api.php @@ -204,7 +204,7 @@ class Api { /** * name:添加链接 */ - public function add_link($token,$fid,$title,$url,$description = '',$weight = 0,$property = 0,$url_standby = ''){ + public function add_link($token,$fid,$title,$url,$description = '',$weight = 0,$property = 0,$url_standby = '',$font_icon=''){ $this->auth($token); $fid = intval($fid); //检测链接是否合法 @@ -225,7 +225,8 @@ class Api { 'description' => htmlspecialchars($description,ENT_QUOTES), 'add_time' => time(), 'weight' => $weight, - 'property' => $property + 'property' => $property, + 'font_icon' => $font_icon ]; //插入数据库 $re = $this->db->insert('on_links',$data); @@ -531,6 +532,45 @@ class Api { } } } + + /** + * 图标上传 + * type:上传类型 + */ + public function uploadImages($token,$type){ + $this->auth($token); + if ($_FILES["file"]["error"] > 0) + { + $this->err_msg(-1015,'File upload failed!'); + } + else + { + //根据时间生成文件名 + $filename = $_FILES["file"]["name"]; + //获取文件后缀 + $suffix = explode('.',$filename); + $suffix = strtolower(end($suffix)); + + //临时文件位置 + $temp = $_FILES["file"]["tmp_name"]; + if( $suffix != 'ico' && $suffix != 'jpg' && $suffix != 'png' && $suffix != 'bmp' ) { + //删除临时文件 + unlink($filename); + $this->err_msg(-1014,'Unsupported file suffix name!'); + } + + $newfilename='upload/'.time().'.'.$suffix; + + if( copy($temp,$newfilename) ) { + $data = [ + 'code' => 0, + 'file_name' => $newfilename + ]; + exit(json_encode($data)); + } + } + } + /** * 导出HTML链接进行备份 */ diff --git a/controller/api.php b/controller/api.php index e95020a..d551e3f 100755 --- a/controller/api.php +++ b/controller/api.php @@ -107,8 +107,9 @@ function add_link($api){ $description = empty($_POST['description']) ? '' : $_POST['description']; $weight = empty($_POST['weight']) ? 0 : intval($_POST['weight']); $property = empty($_POST['property']) ? 0 : 1; - - $api->add_link($token,$fid,$title,$url,$description,$weight,$property,$url_standby); + $font_icon = empty($_POST['font_icon']) ? '' : $_POST['font_icon']; + + $api->add_link($token,$fid,$title,$url,$description,$weight,$property,$url_standby,$font_icon); } /** @@ -239,6 +240,14 @@ function upload($api){ $type = $_GET['type']; $api->upload($token,$type); } +// 上传图标 +function uploadImages($api){ + //获取token + $token = empty( $_POST['token'] ) ? $_GET['token'] : $_POST['token']; + //获取上传类型 + $type = $_GET['type']; + $api->uploadImages($token,$type); +} //书签导入 function imp_link($api) { //获取token diff --git a/controller/click.php b/controller/click.php index 523d6f3..687d77e 100755 --- a/controller/click.php +++ b/controller/click.php @@ -13,7 +13,7 @@ if(empty($id)) { } //查询链接信息 -$link = $db->get('on_links',['id','fid','url','url_standby','property','click','title','description'],[ +$link = $db->get('on_links',['id','fid','url','url_standby','property','click','title','description','font_icon'],[ 'id' => $id ]); diff --git a/templates/admin/add_link.php b/templates/admin/add_link.php index e96e4fd..de6288b 100755 --- a/templates/admin/add_link.php +++ b/templates/admin/add_link.php @@ -30,6 +30,20 @@ +
+ +
+ +
+
+ +
+ +
+ +
+
+
diff --git a/templates/admin/static/embed.js b/templates/admin/static/embed.js index 48d68c8..9f5ac90 100755 --- a/templates/admin/static/embed.js +++ b/templates/admin/static/embed.js @@ -90,7 +90,7 @@ layui.use(['element','table','layer','form','upload','iconHhysFa'], function(){ ,{field: 'font_icon', title: '图标', width:60, templet:function(d){ if(d.font_icon==null) { - return ''; + return ''; } else { @@ -733,6 +733,27 @@ layui.use(['element','table','layer','form','upload','iconHhysFa'], function(){ } }); + upload.render({ + elem: '#iconUpload' //绑定元素 + ,url: 'index.php?c=api&method=uploadImages' //上传接口 + ,accept:'file' + ,exts: 'ico|jpg|png|bmp' + ,done: function(res){ + //console.log(res); + //上传完毕回调 + if( res.code == 0 ) { + $("#font_icon").val(res.file_name); + } + else if( res.code < 0) { + layer.msg(res.err_msg, {icon: 5}); + layer.close(); + } + + } + ,error: function(){ + //请求异常回调 + } + }); }); function get_link_info() { diff --git a/static/images/default.png b/upload/default.png similarity index 100% rename from static/images/default.png rename to upload/default.png