diff --git a/README.md b/README.md index 7f7fb61..9daa601 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # ImgURL -ImgURL是一款简单、纯粹的图床程序,使用PHP + SQLite 3开发,不需要复杂的配置,做到开箱即用。 +ImgURL是一款简单、纯粹的图床程序,使用PHP + SQLite 3开发,不需要复杂的配置,开箱即用。 ### 环境要求 * PHP >= 5.6 @@ -13,11 +13,20 @@ ImgURL是一款简单、纯粹的图床程序,使用PHP + SQLite 3开发,不 - [x] 限制访客上传数量 - [x] 图片压缩 - [x] 图片鉴黄 +- [x] API上传 - [ ] 图片水印 -- [ ] API上传 + ### 更新日志 +#### v1.3 - 2018.09.11 +* 新增粘贴上传(Ctrl + V) +* 期待已久的API上传 +* 后台新增按时间筛选图片 +* 优化“探索发现”,之前为随机显示12张,现在显示本月所有图片(流加载) +* 优化后台“看图模式” +* 修复一些BGU,优化CSS + #### v1.2 - 2018.08.11 * 增加URL批量上传 * 去掉一些不必要的菜单 diff --git a/admin/picadmin.php b/admin/picadmin.php index 65b91a0..0462ef8 100644 --- a/admin/picadmin.php +++ b/admin/picadmin.php @@ -6,10 +6,27 @@ // 获取类型 $type = $_GET['type']; + //获取时间 + @$date = $_GET['date']; + //如果时间不为空 + if($date != ''){ + $thedate = explode("|",$date); + $starttime = $thedate[0]; + $endtime = $thedate[1]; + //翻页选项 + $thepage = '&date='.$date; + } + else{ + $starttime = ''; + //获取当前日期 + $endtime = date("Y-m-d",time()); + //翻页选项 + $thepage = ''; + } //获取页数 $page = $_GET['page']; //查询图片 - $imgs = $pic->querypic($type,$page); + $imgs = $pic->newquery($type,$date); $up = (int)$page - 1; if($up <= 0){ @@ -26,25 +43,34 @@
-
+
+ +
+ + + + + + + + + + +
按时间筛选: -
+
+
- 图片ID: <?php echo $id; ?> + 图片ID: <?php echo $id; ?>
-
- -
+
diff --git a/admin/senioradmin.php b/admin/senioradmin.php index e1e7c34..c34063e 100644 --- a/admin/senioradmin.php +++ b/admin/senioradmin.php @@ -54,7 +54,7 @@ - - + diff --git a/admin/smadmin.php b/admin/smadmin.php index c0f8ef0..f293ae6 100644 --- a/admin/smadmin.php +++ b/admin/smadmin.php @@ -34,7 +34,7 @@
- ID: <?php echo $img['id']; ?> + ID: <?php echo $img['id']; ?>
diff --git a/found.php b/found.php index 73939cc..beb9c7e 100644 --- a/found.php +++ b/found.php @@ -10,14 +10,15 @@ //初始化 $domain = $config['domain']; $userdir = $config['userdir']; - $sql = "SELECT `id`,`path` FROM `imginfo` WHERE (`dir` = '$userdir' AND `level` < 3 AND `date` LIKE '$thetime%') ORDER BY random() LIMIT 12"; + //$sql = "SELECT `id`,`path` FROM `imginfo` WHERE (`dir` = '$userdir' AND `level` < 3 AND `date` LIKE '$thetime%') ORDER BY random() LIMIT 12"; + $sql = "SELECT `id`,`path` FROM `imginfo` WHERE (`dir` = '$userdir' AND `level` < 3 AND `date` LIKE '$thetime%') ORDER BY `id` DESC"; $datas = $database->query($sql)->fetchAll(); ?>
-
此页面随机显示本月12张图片,刷新页面可重新随机,如果不显示说明本月暂未上传图片。
+
此页面显示本月上传图片,如果不显示说明本月暂未上传图片。
- +
diff --git a/functions/api.php b/functions/api.php new file mode 100644 index 0000000..c12e680 --- /dev/null +++ b/functions/api.php @@ -0,0 +1,120 @@ +re_error('未选择文件!'); + } + //检查用户是否登录 + $status = $basis->check($config); + + //检查用户是否登陆来判断上传目录 + if($status == 'islogin') { + //设置上传路径 + $updir = $config['admindir']; + } + else{ + $updir = $config['userdir']; + //限制用户上传数量 + $basis->limitnum(); + } + + //获取上传者信息 + $ip = $basis->getip(); + $ua = $_SERVER['HTTP_USER_AGENT']; + $date = date('Y-m-d',time()); + //载入上传类 + include('./class/class.upload.php'); + + //上传方法 + $handle = new upload($_FILES['file']); + if ($handle->uploaded) { + $handle->file_new_name_body = 'image_resized'; + //允许上传大小2m + $handle->file_max_size = '2097152'; + //允许的MIME类型,仅运行上传图片 + $handle->allowed = array('image/*'); + + // 当前月份 + $current_time = date('ym',time()); + //上传路径:目录 + 时间 + $handle->process('../'.$updir.'/'.$current_time."/"); + if ($handle->processed) { + //获取站点域名 + $domain = $config['domain']; + //生成文件hash + $fhash = hash_file("md5",$handle->file_dst_pathname,FALSE); + $fhash = substr($fhash,8,16); + //新的文件名(../temp/1804/\d64c8036c0605175.jpg) + $new_img = $handle->file_dst_path.$fhash.'.'.$handle->file_dst_name_ext; + //图片URL地址 + $imgurl = $domain.$updir.'/'.$current_time.'/'.$fhash.'.'.$handle->file_dst_name_ext; + //图片路径(temp/1804/d64c8036c0605175.jpg) + $imgdir = $updir.'/'.$current_time.'/'.$fhash.'.'.$handle->file_dst_name_ext; + + //判断文件是否已经存在 + if(!is_file($new_img)) { + //对文件更名 + rename($handle->file_dst_pathname,$new_img); + } + else{ + //删除原始文件 + unlink($handle->file_dst_pathname); + } + + //检查某张图片是否已经上传过,如果已经上传了,直接返回数据并终止操作 + $basis->isupload($imgdir); + + //没有上传过的图片,继续写入数据库 + $last_user_id = $database->insert("imginfo", [ + "path" => $imgdir, + "ip" => $ip, + "ua" => $ua, + "date" => $date, + "dir" => $updir, + "compress" => 0, + "level" => 0 + ]); + //返回最后的ID + $account_id = $database->id(); + //上传成功,返回json数据 + $redata = array( + "code" => 1, + "id" => $account_id, + "url" => $imgurl, + "width" => $handle->image_dst_x, + "height" => $handle->image_dst_y + ); + + //直接返回图片URL + if($type == 'url'){ + echo $imgurl; + } + else{ + //返回json + echo $redata = json_encode($redata); + } + + $handle->clean(); + //继续请求鉴黄接口 + $basis->curlZip($account_id,$config['domain']); + } else { + //上传出现错误,返回报错信息 + $redata = array( + "code" => 0, + "msg" => $handle->error + ); + echo json_encode($redata); + } + } +?> \ No newline at end of file diff --git a/functions/class/class.admin.php b/functions/class/class.admin.php index bc1df81..9b850c9 100644 --- a/functions/class/class.admin.php +++ b/functions/class/class.admin.php @@ -93,6 +93,53 @@ break; } } + //新版查询图片 + function newquery($type,$date = null){ + //echo $type; + //exit; + //获取当前时间 + $thetime = date('Y-m',time()); + //对时间进行拆分 + if($date != null){ + $date = explode("|",$date); + + $starttime = $date[0]; + $endttime = $date[1]; + } + + $config = $this->config; + $database = $this->database; + + //判断类型 + switch ($type) { + case 'user': + // echo 'dsd'; + $datas = $database->select("imginfo", "*", [ + "dir" => $config['userdir'], + "date[~]" => $thetime, + "ORDER" => ["id" => "DESC"] + ]); + // var_dump( $database->log() ); + // exit; + return $datas; + break; + case 'admin': + $datas = $database->select("imginfo", "*", [ + "dir" => $config['admindir'], + "date[~]" => $thetime, + "ORDER" => ["id" => "DESC"] + ]); + return $datas; + break; + default: + $sql = "SELECT * FROM imginfo WHERE date(date) BETWEEN '$starttime' AND '$endttime' ORDER BY `id` DESC"; + + $datas = $database->query($sql); + //var_dump($database->log()); + return $datas; + break; + } + } //删除一张图片 function delete($id){ $config = $this->config; diff --git a/functions/class/class.user.php b/functions/class/class.user.php index 809cc6a..45db975 100644 --- a/functions/class/class.user.php +++ b/functions/class/class.user.php @@ -143,6 +143,36 @@ break; } } + //返回错误json + function re_error($msg){ + $arr = array( + "code" => 0, + "msg" => $msg + ); + $rejson = json_encode($arr); + echo $rejson; + exit; + } + //请求tipng和鉴黄接口 + function curlZip($id,$domain){ + //组合为完整的接口 + $apiurl = $domain.'dispose.php?id='.$id; + //请求接口 + $curl = curl_init($apiurl); + + curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"); + curl_setopt($curl, CURLOPT_FAILONERROR, true); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + #设置超时时间,最小为1s(可选) + curl_setopt($curl , CURLOPT_TIMEOUT, 2); + + @curl_exec($curl); + curl_close($curl); + //var_dump($html); + } } //自动初始化完成一些基础操作 diff --git a/functions/upload.php b/functions/upload.php index c1ebc75..3717b32 100644 --- a/functions/upload.php +++ b/functions/upload.php @@ -1,9 +1,16 @@ re_error('非法请求!'); + } + //检查用户是否登录 $status = $basis->check($config); + //检查用户是否登陆来判断上传目录 if($status == 'islogin') { //设置上传路径 diff --git a/functions/version.txt b/functions/version.txt index 75ca56c..70371cb 100644 --- a/functions/version.txt +++ b/functions/version.txt @@ -1 +1 @@ -v1.21(20180831) \ No newline at end of file +v1.3(20180911) \ No newline at end of file diff --git a/index.php b/index.php index 5013068..46ac27f 100644 --- a/index.php +++ b/index.php @@ -6,11 +6,11 @@
-
注意:您上传的图片将会公开显示,勿上传隐私图片。游客限制每天5张,最大支持2M
+
注意:您上传的图片将会公开显示,勿上传隐私图片。游客限制每天10张,最大支持2M
-

点击上传,或将图片拖拽到此处

+

将图片拖拽到此处,支持Ctrl + V粘贴上传

@@ -19,7 +19,7 @@
-
+