Browse Source

v 1.2

pull/16/head
xiaoz 6 years ago
parent
commit
534dd157e8
  1. 2
      .gitignore
  2. 65
      admin/urlup.php
  3. 116
      functions/class/class.admin.php
  4. 7
      functions/urlup.php
  5. 36
      static/embed.js
  6. 3
      static/style.css
  7. 2
      tpl/admin/footer.php
  8. 3
      tpl/admin/header.php
  9. 1
      tpl/admin/left.php
  10. 2
      tpl/user/footer.php
  11. 2
      tpl/user/header.php

2
.gitignore vendored

@ -1,2 +1,4 @@
temp/ temp/
upload/ upload/
1808/
db/

65
admin/urlup.php

@ -0,0 +1,65 @@
<?php
$title = "URL批量上传 - ImgURL";
include_once("../functions/class/class.admin.php");
// 载入头部
include_once("../tpl/admin/header.php");
// 获取类型
$type = $_GET['type'];
//获取页数
$page = $_GET['page'];
//查询sm.ms图片
$imgs = $pic->querysm($page);
//var_dump($imgs);
$up = (int)$page - 1;
if($up <= 0){
$up = 1;
}
$down = (int)$page +1;
?>
<div class="layui-container" style = "margin-top:2em;">
<div class="layui-row layui-col-space20">
<div class="layui-col-lg3">
<!-- 载入左侧导航栏 -->
<?php include_once("../tpl/admin/left.php"); ?>
</div>
<!-- 后台内容部分 -->
<div id = "adminpic">
<div class="layui-col-lg9">
<?php if($type == 'preview') { ?>
<!-- 预览图片 -->
<div class="layui-col-lg9 layui-col-space10">
<?php foreach ($imgs as $img) {
?>
<div class="layui-col-lg4 picadmin">
<img lay-src="<?php echo $img['url']; ?>" layer-src="<?php echo $img['url']; ?>" alt="ID: <?php echo $img['id']; ?>" />
</div>
<?php } ?>
</div>
<?php }else{ ?>
<!-- 预览图片END -->
<!-- 表格 -->
<table class="layui-table">
<div class="msg" style = "margin-top:0;"><i class="layui-icon"></i> 请输入图片地址,一行一个,一次不超过10个</div>
<div class="urltext">
<textarea rows="10" id = "arrurl" name="desc" placeholder="请输入图片地址,一行一个" class="layui-textarea"></textarea>
</div>
<div style = "margin-top:1em;">
<a href="javscript:;" class="layui-btn" onclick = "urlup()">开始上传</a>
</div>
</table>
<?php } ?>
<!-- 表格END -->
</div>
<!-- 后台内容部分END -->
</div>
</div>
<?php
// 载入页脚
// 载入头部
include_once("../tpl/admin/footer.php");
?>

116
functions/class/class.admin.php

@ -69,6 +69,14 @@
]); ]);
return $datas; return $datas;
break; break;
case 'unidentification':
$datas = $database->select("imginfo", "*", [
"level" => '',
"ORDER" => ["id" => "DESC"],
"LIMIT" => [$start,$num]
]);
return $datas;
break;
default: default:
echo 'dsddsd'; echo 'dsddsd';
break; break;
@ -208,6 +216,114 @@
curl_close($curl); curl_close($curl);
echo 'ok'; 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); $pic = new Admin($config,$database);

7
functions/urlup.php

@ -0,0 +1,7 @@
<?php
include_once("class/class.admin.php");
@$arr = $_POST['arr'];
$pic->urlup($arr);
?>

36
static/embed.js

@ -409,3 +409,39 @@ function hideimg(id){
id = "viewimg" + id; id = "viewimg" + id;
$("#" + id).hide(); $("#" + 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);
}
});
}

3
static/style.css

@ -202,3 +202,6 @@
margin-left:auto; margin-left:auto;
margin-right:auto; margin-right:auto;
} }
.urltext{
margin-top:2em;
}

2
tpl/admin/footer.php

@ -13,6 +13,6 @@
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script> <script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="../static/layui/layui.js"></script> <script src="../static/layui/layui.js"></script>
<script src="../static/embed.js?v=1.12"></script> <script src="../static/embed.js?v=1.2"></script>
</body> </body>
</html> </html>

3
tpl/admin/header.php

@ -11,7 +11,7 @@
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<link rel="Bookmark" href="../favicon.ico" /> <link rel="Bookmark" href="../favicon.ico" />
<link rel="stylesheet" href="../static/layui/css/layui.css"> <link rel="stylesheet" href="../static/layui/css/layui.css">
<link rel="stylesheet" href="../static/style.css?v=1.12"> <link rel="stylesheet" href="../static/style.css?v=1.2">
<script src = "https://libs.xiaoz.top/clipBoard.js/clipBoard.min.js"></script> <script src = "https://libs.xiaoz.top/clipBoard.js/clipBoard.min.js"></script>
</head> </head>
<body> <body>
@ -23,6 +23,7 @@
<div class="left-menu"><a href="../"><h1>ImgURL</h1></a></div> <div class="left-menu"><a href="../"><h1>ImgURL</h1></a></div>
<ul class="layui-nav menu" lay-filter=""> <ul class="layui-nav menu" lay-filter="">
<li class="layui-nav-item"><a href="./"><i class="layui-icon">&#xe68e;</i> 后台首页</a></li> <li class="layui-nav-item"><a href="./"><i class="layui-icon">&#xe68e;</i> 后台首页</a></li>
<li class="layui-nav-item"><a href="./urlup.php"><i class="layui-icon">&#xe64c;</i> URL上传</a></li>
</ul> </ul>
<div class="right-menu"> <div class="right-menu">
<ul class="layui-nav menu" lay-filter=""> <ul class="layui-nav menu" lay-filter="">

1
tpl/admin/left.php

@ -16,6 +16,7 @@
<dd><a href="senioradmin.php?type=admin&page=1">管理员上传</a></dd> <dd><a href="senioradmin.php?type=admin&page=1">管理员上传</a></dd>
<dd><a href="smadmin.php?type=admin&page=1">SM.MS</a></dd> <dd><a href="smadmin.php?type=admin&page=1">SM.MS</a></dd>
<dd><a href="senioradmin.php?type=dubious&page=1">可疑图片</a></dd> <dd><a href="senioradmin.php?type=dubious&page=1">可疑图片</a></dd>
<dd><a href="senioradmin.php?type=unidentification&page=1">未识别图片</a></dd>
</dl> </dl>
</li> </li>
<li class="layui-nav-item layui-nav-itemed"> <li class="layui-nav-item layui-nav-itemed">

2
tpl/user/footer.php

@ -18,6 +18,6 @@
<!-- 底部END --> <!-- 底部END -->
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script> <script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="./static/layui/layui.js"></script> <script src="./static/layui/layui.js"></script>
<script src="./static/embed.js?v=1.12"></script> <script src="./static/embed.js?v=1.2"></script>
</body> </body>
</html> </html>

2
tpl/user/header.php

@ -12,7 +12,7 @@
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="Bookmark" href="favicon.ico" /> <link rel="Bookmark" href="favicon.ico" />
<link rel="stylesheet" href="./static/layui/css/layui.css"> <link rel="stylesheet" href="./static/layui/css/layui.css">
<link rel="stylesheet" href="./static/style.css?v=1.12"> <link rel="stylesheet" href="./static/style.css?v=1.2">
<script src = "https://libs.xiaoz.top/clipBoard.js/clipBoard.min.js"></script> <script src = "https://libs.xiaoz.top/clipBoard.js/clipBoard.min.js"></script>
</head> </head>
<body> <body>

Loading…
Cancel
Save