Browse Source

增加功能

pull/16/head
xiaoz 6 years ago
parent
commit
6816cbafbf
  1. 17
      functions/class/class.user.php
  2. 81
      functions/cvupload.php
  3. 105
      miniup.html
  4. 3
      static/index.js

17
functions/class/class.user.php

@ -127,7 +127,22 @@
} }
return $ip; return $ip;
} }
//判断文件MIME类型
function mime($path){
$mime = mime_content_type($path);
switch ( $mime )
{
case 'image/gif':
case 'image/png':
case 'image/jpeg':
case 'image/bmp':
return true;
break;
default:
return false;
break;
}
}
} }
//自动初始化完成一些基础操作 //自动初始化完成一些基础操作

81
functions/cvupload.php

@ -20,39 +20,72 @@
$ua = $_SERVER['HTTP_USER_AGENT']; $ua = $_SERVER['HTTP_USER_AGENT'];
$date = date('Y-m-d',time()); $date = date('Y-m-d',time());
//图片存储路径 //根据IP、ua、时间生成一个唯一的md5值
$picpath = $updir.'/'.date('ym',time()).'/'.'dsdds.png'; $picname = md5($ip.$ua.date('Y-m-d H:i:s',time()));
//截取16个字符
$picname = substr($picname,8,16).'.png';
$onepath = $updir.'/'.date('ym',time()).'/'.$picname;
//图片完整存储路径
$picpath = APP.$onepath;
//接受base64图片 //echo $picpath;
//替换一下,以免windows出现问题
$picpath = str_replace("\\","/",$picpath);
//echo $picpath;
//接接收ase64图片
$picfile = $_POST['content']; $picfile = $_POST['content'];
$picfile = base64_decode($picfile); $picfile = base64_decode($picfile);
//echo $picfile; //echo $picfile;
//存储图片 //存储图片
var_dump(file_put_contents("D:/wwwroot/imgurl/upload/1809/dsd.png", $picfile)); file_put_contents($picpath, $picfile);
//获取文件mime类型
//如果不是图片文件,终止执行
if(!$basis->mime($picpath)){
unlink($picpath);
$arr = array(
"code" => 0,
"msg" => '不允许的文件类型'
);
$json = json_encode($arr);
echo $json;
exit;
}
//继续执行并写入数据库
$last_user_id = $database->insert("imginfo", [
"path" => $onepath,
"ip" => $ip,
"ua" => $ua,
"date" => $date,
"dir" => $updir,
"compress" => 0,
"level" => 0
]);
//var_dump($database->log());
//返回最后的ID
$account_id = $database->id();
//写入数据库成功,返回json数据
if($last_user_id){
$url = $config['domain'].$onepath;
rejson(1,$url,$account_id);
}
//echo $picpath; //echo $picpath;
//var_dump($picfile); //var_dump($picfile);
?> ?>
<?php <?php
function base64_image_content($base64_image_content,$path){ //返回json数据
//匹配出图片的格式 function rejson($code,$url,$id = 0){
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)){ $arr = array(
$type = $result[2]; "code" => $code,
$new_file = $path."/".date('Ymd',time())."/"; "url" => $url,
if(!file_exists($new_file)){ "id" => $id
//检查是否有该文件夹,如果没有就创建,并给予最高权限 );
mkdir($new_file, 0700); $json = json_encode($arr);
} echo $json;
$new_file = $new_file.time().".{$type}"; }
if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content)))){
return '/'.$new_file;
}else{
return false;
}
}else{
return false;
}
}
?> ?>

105
miniup.html

@ -14,7 +14,7 @@
<link rel="stylesheet" href="./static/style.css?v=1.2"> <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>
<style type="text/css" media="screen" id="test"> <style type="text/css" media="screen">
#imgbtn{ #imgbtn{
display: none; display: none;
} }
@ -30,6 +30,7 @@
<ul class="layui-tab-title"> <ul class="layui-tab-title">
<li class="layui-this">ImgURL</li> <li class="layui-this">ImgURL</li>
<li>SM.MS</li> <li>SM.MS</li>
<li>关于</li>
</ul> </ul>
<div class="layui-tab-content"> <div class="layui-tab-content">
<!--上传到ImgURL--> <!--上传到ImgURL-->
@ -37,7 +38,7 @@
<!-- 上传图片表单 --> <!-- 上传图片表单 -->
<div class="layui-upload-drag" id="upimg"> <div class="layui-upload-drag" id="upimg">
<i class="layui-icon">&#xe67c;</i> <i class="layui-icon">&#xe67c;</i>
<p>点击上传,或将图片拖拽到此处</p> <p>将图片拖拽到此处,或将鼠标移动到这里支持Ctrl + V上传</p>
</div> </div>
<!-- 上传图片表单END --> <!-- 上传图片表单END -->
</div> </div>
@ -50,6 +51,35 @@
</a> </a>
</div> </div>
</div> </div>
<!--捐赠-->
<div class="layui-tab-item">
<h1>ImgURL</h1>
<p>ImgURL是一款简洁、纯粹的图床程序,使用PHP + Sqlite开发,开箱即用。</p>
<br /><h2>主要功能</h2><br />
<ul>
<li>拽拖上传图片、实时预览</li>
<li>一键生成链接,一键复制</li>
<li>图片管理</li>
<li>TinyPNG图片压缩</li>
<li>图片智能鉴黄</li>
</ul>
<br /><h2>使用说明</h2><br />
<ul>
<li>图片最大上传限制为2M</li>
<li>游客每天限制上传10张图片</li>
<li>勿上传暴力、色情、反动图片,否则后果自负</li>
<li>如果您使用ImgURL代表同意以上协议</li>
</ul>
<br /><h2>联系我</h2><br />
<ul>
<li>Blog:<a href = "https://www.xiaoz.me/" target = "_blank">https://www.xiaoz.me/</a></li>
<li>QQ:337003006</li>
</ul>
<br />
<p>扫描下方二维码请我喝一杯咖啡</p><br />
<p><img src="https://imgurl.org/upload/1712/cb349aa4a1b95997.png" alt=""></p>
</div>
<!--捐赠-->
</div> </div>
</div> </div>
<!--选项卡END--> <!--选项卡END-->
@ -104,8 +134,9 @@
<script> <script>
//隐藏按钮 //隐藏按钮
//setTimeout('$("#imgbtn").remove()',100) //setTimeout('$("#imgbtn").remove()',100)
layui.use(['element'],function(){ layui.use(['element','layer'],function(){
var element = layui.element; var element = layui.element;
var layer = layui.layer;
element.on('tab(uptab)', function(data){ element.on('tab(uptab)', function(data){
//console.log(this); //当前Tab标题所在的原始DOM元素 //console.log(this); //当前Tab标题所在的原始DOM元素
//console.log(data.index); //得到当前Tab的所在下标 //console.log(data.index); //得到当前Tab的所在下标
@ -115,22 +146,58 @@
var load1 = document.querySelector("body"); var load1 = document.querySelector("body");
// 实例化即可 // 实例化即可
new ctrlVUtil({ new ctrlVUtil({
uploadUrl: "functions/cvupload.php", uploadUrl: "functions/cvupload.php",
targetElement: load1, targetElement: load1,
isCompleteImg:false, isCompleteImg:false,
data:{ data:{
name:"alanzhang" name:"alanzhang",
}, },
success:function(data){ success:function(data){
alert("上传成功"); //转为对象
console.log(data); var res = data;
}, //上传成功
error: function(error){ if(res.code == 1){
alert("上传失败"); layer.closeAll('loading');
} $("#showpic a").attr('href',res.url);
}); $("#showpic img").attr('src',res.url);
$("#url").val(res.url);
$("#html").val("<img src = '" + res.url + "' />");
$("#markdown").val("![](" + res.url + ")");
$("#bbcode").val("[img]" + res.url + "[/img]");
$("#upok").show();
//请求接口处理图片
$.get("./dispose.php?id="+res.id,function(data,status){
var obj = eval('(' + data + ')');
if(obj.level == 3){
layer.open({
title: '温馨提示'
,content: '请勿上传违规图片!'
});
}
if(obj.level == null){
$.get("./dispose.php?id="+res.id,function(data,status){
var obj = eval('(' + data + ')');
if(obj.level == 3){
layer.open({
title: '温馨提示'
,content: '请勿上传违规图片!'
});
}
});
}
});
}
else{
layer.msg(res.msg);
}
},
error: function(error){
layer.closeAll('loading');
alert("上传失败!");
}
});
</script> </script>
</body> </body>
</html> </html>

3
static/index.js

@ -175,6 +175,9 @@
* @return {[type]} [description] * @return {[type]} [description]
*/ */
ctrlVUtil.prototype.send = function(imgcontent) { ctrlVUtil.prototype.send = function(imgcontent) {
//自己添加的,显示上传加载
layer.load();
var that = this; var that = this;
that.uploadInput.innerHTML = ""; that.uploadInput.innerHTML = "";

Loading…
Cancel
Save