diff --git a/.gitignore b/.gitignore index 02f69a3..c295305 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ temp/ upload/ +1808/ +db/ diff --git a/admin/urlup.php b/admin/urlup.php new file mode 100644 index 0000000..f2de983 --- /dev/null +++ b/admin/urlup.php @@ -0,0 +1,65 @@ +querysm($page); + //var_dump($imgs); + + $up = (int)$page - 1; + if($up <= 0){ + $up = 1; + } + $down = (int)$page +1; +?> + +
+
+
+ + +
+ +
+
+ + +
+ +
+ ID: <?php echo $img['id']; ?> +
+ +
+ + + + +
请输入图片地址,一行一个,一次不超过10个
+
+ +
+
+ 开始上传 +
+
+ + +
+ + + +
+
+ \ No newline at end of file diff --git a/functions/class/class.admin.php b/functions/class/class.admin.php index e6e5cf8..8b5a20c 100644 --- a/functions/class/class.admin.php +++ b/functions/class/class.admin.php @@ -68,7 +68,15 @@ "LIMIT" => [$start,$num] ]); return $datas; - break; + break; + case 'unidentification': + $datas = $database->select("imginfo", "*", [ + "level" => '', + "ORDER" => ["id" => "DESC"], + "LIMIT" => [$start,$num] + ]); + return $datas; + break; default: echo 'dsddsd'; break; @@ -208,6 +216,114 @@ curl_close($curl); echo 'ok'; } + //通过URL批量上传图片 + function urlup($arr){ + $config = $this->config; + //$arr参数为一个数组 + $arr = explode("\n",$arr); + //计算URL个数 + $urlnum = count($arr); + //不能超过10个 + if($urlnum > 10){ + $rejson = array( + "code" => 0, + "msg" => "URL链接不能超过10个!" + ); + echo json_encode($rejson); + exit; + } + + //遍历URL并下载图片 + foreach( $arr as $url ) + { + //去掉空格 + $url = trim($url); + //判断是否是URL + if(!filter_var($url, FILTER_VALIDATE_URL)){ + $rejson = array( + "code" => 0, + "msg" => $url."不是有效的地址,程序终止!" + ); + echo json_encode($rejson); + exit; + } + //获取图片后缀 + $suffix = explode(".",$url); + $suffix = end($suffix); + $suffix = strtolower($suffix); + + //如果是图片后缀,使用curl进行抓取 + if(($suffix == 'jpg') || ($suffix == 'jpeg') || ($suffix == 'png') || ($suffix == 'bmp') || ($suffix == 'gif')) { + + $curl = curl_init($url); + + curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"); + 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, 10); + + $html = curl_exec($curl); + curl_close($curl); + + //判断目录是否存在 + $dir = APP.$config['admindir'].'/'.date('ym',time()); + if(!is_dir($dir)){ + mkdir($dir); + } + //生成文件名 + $filenme = $dir.date('Y-m-d H:i:s',time()).$suffix; + $filenme = substr(md5($filenme), 8, 16).'.'.$suffix; + + $full = $dir.'/'.$filenme; + //写入文件 + $myfile = fopen($full, "w") or die("Unable to open file!"); + fwrite($myfile, $html); + fclose($myfile); + $datas = array( + "path" => $config['admindir'].'/'.date('ym',time()).'/'.$filenme, + "dir" => $config['admindir'] + ); + //写入数据库 + $insert = $this->indb($datas); + + } + else{ + $rejson = array( + "code" => 0, + "msg" => "包含无效的图片地址,程序终止!" + ); + echo json_encode($rejson); + exit; + } + + } + $rejson = array( + "code" => 1, + "msg" => "成功上传".$urlnum."张图片!" + ); + echo json_encode($rejson); + exit; + } + + //图片写入数据库 + function indb($datas){ + $database = $this->database; + $date = date('Y-m-d',time()); + $insert = $database->insert("imginfo",[ + "path" => $datas['path'], + "ip" => "127.0.0.1", + "ua" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36", + "date" => $date, + "dir" => $datas['dir'], + "compress" => 0, + "level" => 0 + ]); + return $insert; + } } $pic = new Admin($config,$database); diff --git a/functions/urlup.php b/functions/urlup.php new file mode 100644 index 0000000..7594e77 --- /dev/null +++ b/functions/urlup.php @@ -0,0 +1,7 @@ +urlup($arr); +?> \ No newline at end of file diff --git a/static/embed.js b/static/embed.js index bd336be..b6ea7e0 100644 --- a/static/embed.js +++ b/static/embed.js @@ -408,4 +408,40 @@ function viewimg(id,imgurl){ function hideimg(id){ id = "viewimg" + id; $("#" + id).hide(); +} + +//URL上传 +function urlup(){ + layui.use('layer', function(){ + var layer = layui.layer; + layer.open({ + type:3 + ,content: '上传中,请等待...' + }); + }); + arr = $("#arrurl").val(); + //如果地址为空 + if(arr == ''){ + layer.closeAll('loading'); + layer.msg('地址不能为空!'); + return false; + } + + $.post("../functions/urlup.php",{arr:arr},function(data,status){ + var re = eval('(' + data + ')'); + if(re.code == 1){ + //关闭加载层 + layer.closeAll('loading'); + layer.msg(re.msg); + } + else if(re.code == 0){ + //关闭加载层 + layer.closeAll('loading'); + layer.msg(re.msg); + } + else{ + layer.closeAll('loading'); + layer.msg(re.msg); + } + }); } \ No newline at end of file diff --git a/static/style.css b/static/style.css index 1751619..c736780 100644 --- a/static/style.css +++ b/static/style.css @@ -201,4 +201,7 @@ width:680px; margin-left:auto; margin-right:auto; +} +.urltext{ + margin-top:2em; } \ No newline at end of file diff --git a/tpl/admin/footer.php b/tpl/admin/footer.php index 60b74d3..240d473 100644 --- a/tpl/admin/footer.php +++ b/tpl/admin/footer.php @@ -13,6 +13,6 @@ - + \ No newline at end of file diff --git a/tpl/admin/header.php b/tpl/admin/header.php index 316d618..07f78f8 100644 --- a/tpl/admin/header.php +++ b/tpl/admin/header.php @@ -11,7 +11,7 @@ - + @@ -23,6 +23,7 @@

ImgURL