|
|
|
@ -69,6 +69,14 @@
@@ -69,6 +69,14 @@
|
|
|
|
|
]); |
|
|
|
|
return $datas; |
|
|
|
|
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 @@
@@ -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); |
|
|
|
|