mirror of https://github.com/helloxz/imgurl.git
xiaoz
7 years ago
8 changed files with 477 additions and 0 deletions
@ -0,0 +1,6 @@
@@ -0,0 +1,6 @@
|
||||
<?php |
||||
$config = array( |
||||
'domain' => 'http://localhost/imgurl/', |
||||
'watermark' => 'false' |
||||
); |
||||
?> |
@ -0,0 +1,94 @@
@@ -0,0 +1,94 @@
|
||||
<!DOCTYPE html> |
||||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> |
||||
<head> |
||||
<meta charset="utf-8" /> |
||||
<title>newindex</title> |
||||
<meta name="generator" content="EverEdit" /> |
||||
<meta name="author" content="" /> |
||||
<meta name="keywords" content="" /> |
||||
<meta name="description" content="" /> |
||||
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> |
||||
<link href="./static/uploadfile.css" rel="stylesheet"> |
||||
<link href="./static/style.css" rel="stylesheet"> |
||||
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script> |
||||
<script src="./static/jquery.uploadfile.min.js"></script> |
||||
<script src = "https://libs.xiaoz.top/clipBoard.js/clipBoard.min.js"></script> |
||||
<script src = "./js/embed.js"></script> |
||||
</head> |
||||
<body> |
||||
<div id="msg"> |
||||
<div class = "msg">复制成功!</div> |
||||
</div> |
||||
<div id = "loading"><center><img src="./static/ajax-load.gif" alt="" class = "img-responsive center-block"></center></div> |
||||
<!--导航栏--> |
||||
<div id="menu"> |
||||
<div class="container"> |
||||
<div class="row"> |
||||
<div class="col-lg-8 col-md-offset-2"> |
||||
<nav class="navbar navbar-inverse" role="navigation"> |
||||
<div class="container-fluid"> |
||||
<div class="navbar-header"> |
||||
<a class="navbar-brand" href="#">ImgURL</a> |
||||
</div> |
||||
<div> |
||||
<ul class="nav navbar-nav"> |
||||
<li><a href="#">探索发现</a></li> |
||||
<li><a href="#">关于</a></li> |
||||
</ul> |
||||
</div> |
||||
</div> |
||||
</nav> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<!--导航栏END--> |
||||
<div class="container" style = "margin-bottom:40px;"> |
||||
<div class="row"> |
||||
<div class="col-lg-8 col-md-offset-2"> |
||||
<div id="fileuploader">Upload</div> |
||||
|
||||
<!--显示--> |
||||
<div class="table-responsive" id = "relink"> |
||||
<table class="table"> |
||||
<tbody> |
||||
<tr> |
||||
<td width = "15%">URL</td> |
||||
<td width = "75%"><input type="text" id = "linkurl" class="form-control"></td> |
||||
<td width = "10%"><a href="javascript:;" class="btn btn-info" onclick = "copy('linkurl');">复制</a></td> |
||||
</tr> |
||||
<tr> |
||||
<td>HTML</td> |
||||
<td><input type="text" id = "htmlurl" class="form-control"></td> |
||||
<td><a href="javascript:;" class="btn btn-info" onclick = "copy('htmlurl');">复制</a></td> |
||||
</tr> |
||||
<tr> |
||||
<td>MarkDown</td> |
||||
<td><input type="text" id = "mdurl" class="form-control"></td> |
||||
<td><a href="javascript:;" class="btn btn-info" onclick = "copy('mdurl');">复制</a></td> |
||||
</tr> |
||||
<tr> |
||||
<td>BBcode</td> |
||||
<td><input type="text" id = "bbcode" class="form-control"></td> |
||||
<td><a href="javascript:;" class="btn btn-info" onclick = "copy('bbcode');">复制</a></td> |
||||
</tr> |
||||
</tbody> |
||||
</table> |
||||
<div id = "img-box"> |
||||
<a href="" id = "img-url" target = "_blank"><img id = "show_img" src="" alt="" class = "img-responsive center-block img-thumbnail" width = "100%;" height = "100%;"></a> |
||||
</div> |
||||
</div> |
||||
<!--显示--> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<!--页脚--> |
||||
<div id = "footer"> |
||||
<div class="container"> |
||||
<div class="row"> |
||||
<div class="col-lg-8 col-md-offset-2">Copyright Ⓒ 2017 请勿上传违反中国大陆和香港法律的图片,违者后果自负。</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</body> |
||||
</html> |
After Width: | Height: | Size: 24 KiB |
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
$(document).ready(function() |
||||
{ |
||||
$("#fileuploader").uploadFile({ |
||||
url:"./upload.php", |
||||
maxFileSize:"2097152", |
||||
allowedTypes:"jpg,png,gif,bmp", |
||||
showStatusAfterSuccess:"false", |
||||
dragdropWidth:"100%", |
||||
|
||||
|
||||
//允许上传最大文件数量
|
||||
//showDone:"false"
|
||||
//showQueueDiv: "output"
|
||||
onSubmit:function(files) |
||||
{ |
||||
$("#loading").show(); |
||||
}, |
||||
onSuccess:function(files,data,xhr,pd) |
||||
{ |
||||
$("#loading").hide(); |
||||
$("#relink").show(); |
||||
var imginfo = new Function("return" + data)(); |
||||
document.getElementById("linkurl").value = imginfo.linkurl; |
||||
document.getElementById("htmlurl").value = "<img src = '" + imginfo.linkurl + "' />"; |
||||
document.getElementById("mdurl").value = "![](" + imginfo.linkurl + ")"; |
||||
document.getElementById("bbcode").value = "[img]" + imginfo.linkurl + "[/img]"; |
||||
$("#show_img").attr('src',imginfo.linkurl); |
||||
$("#img-url").attr('href',imginfo.linkurl); |
||||
$("#img-box").show(); |
||||
} |
||||
}); |
||||
}); |
||||
|
||||
//复制按钮
|
||||
function copy(url) { |
||||
|
||||
new clipBoard($("#url"),{ |
||||
copy: function() { |
||||
return $("#" + url).val(); |
||||
}, |
||||
afterCopy: function() { |
||||
$("#msg").show(); |
||||
$("#msg").fadeOut(1500); |
||||
} |
||||
}); |
||||
} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,74 @@
@@ -0,0 +1,74 @@
|
||||
.ajax-file-upload-container { |
||||
display: none; |
||||
} |
||||
|
||||
#fileuploader { |
||||
width:100%; |
||||
} |
||||
.ajax-upload-dragdrop { |
||||
height:200px; |
||||
} |
||||
.ajax-file-upload { |
||||
margin-left:auto; |
||||
margin-right:auto; |
||||
} |
||||
|
||||
#loading{ |
||||
margin:0; |
||||
padding:0; |
||||
display:none; |
||||
width:100%; |
||||
position:fixed; |
||||
} |
||||
#fileuploader { |
||||
margin-top:10%; |
||||
} |
||||
#relink{ |
||||
display: none; |
||||
margin-top:36px; |
||||
} |
||||
#relink lable{ |
||||
color:#2BD5AA; |
||||
padding:10px; |
||||
} |
||||
#msg{ |
||||
margin:0; |
||||
padding:0; |
||||
width:100%; |
||||
position:fixed; |
||||
display: none; |
||||
z-index: 100; |
||||
top:60px; |
||||
} |
||||
.msg{ |
||||
color:green; |
||||
border:1px solid #EFEFEF; |
||||
background-color:#E6E6E6; |
||||
text-align:center; |
||||
padding:12px; |
||||
border-radius:5px; |
||||
width:16%; |
||||
margin:auto; |
||||
font-size:16px; |
||||
} |
||||
#img-box{ |
||||
margin-bottom:20px; |
||||
} |
||||
#menu{ |
||||
margin:0; |
||||
padding:0; |
||||
width:100%; |
||||
background-color:#222222; |
||||
} |
||||
#menu .navbar { |
||||
margin-bottom:0; |
||||
} |
||||
|
||||
#footer{ |
||||
width:100%; |
||||
background-color: #F5F5F5; |
||||
color:#999999; |
||||
position:fixed; |
||||
bottom:0; |
||||
padding:14px; |
||||
} |
@ -0,0 +1,146 @@
@@ -0,0 +1,146 @@
|
||||
.ajax-file-upload-statusbar { |
||||
border: 1px solid #0ba1b5; |
||||
margin-top: 10px; |
||||
width: 420px; |
||||
margin-right: 10px; |
||||
margin: 5px; |
||||
-moz-border-radius: 4px; |
||||
-webkit-border-radius: 4px; |
||||
border-radius: 4px; |
||||
padding: 5px 5px 5px 15px |
||||
} |
||||
|
||||
.ajax-file-upload-filename { |
||||
width: 300px; |
||||
height: auto; |
||||
margin: 0 5px 5px 0px; |
||||
|
||||
} |
||||
|
||||
.ajax-file-upload-filesize { |
||||
width: 50px; |
||||
height: auto; |
||||
margin: 0 5px 5px 0px; |
||||
display: inline-block; |
||||
vertical-align:middle; |
||||
} |
||||
.ajax-file-upload-progress { |
||||
margin: 5px 10px 5px 0px; |
||||
position: relative; |
||||
width: 250px; |
||||
border: 1px solid #ddd; |
||||
padding: 1px; |
||||
border-radius: 3px; |
||||
display: inline-block; |
||||
color:#FFFFFF; |
||||
|
||||
} |
||||
.ajax-file-upload-bar { |
||||
background-color: #0ba1b5; |
||||
width: 0; |
||||
height: 20px; |
||||
border-radius: 3px; |
||||
color:#FFFFFF; |
||||
|
||||
} |
||||
.ajax-file-upload-percent { |
||||
position: absolute; |
||||
display: inline-block; |
||||
top: 3px; |
||||
left: 48% |
||||
} |
||||
.ajax-file-upload-red { |
||||
-moz-box-shadow: inset 0 39px 0 -24px #e67a73; |
||||
-webkit-box-shadow: inset 0 39px 0 -24px #e67a73; |
||||
box-shadow: inset 0 39px 0 -24px #e67a73; |
||||
background-color: #e4685d; |
||||
-moz-border-radius: 4px; |
||||
-webkit-border-radius: 4px; |
||||
border-radius: 4px; |
||||
display: inline-block; |
||||
color: #fff; |
||||
font-family: arial; |
||||
font-size: 13px; |
||||
font-weight: normal; |
||||
padding: 4px 15px; |
||||
text-decoration: none; |
||||
text-shadow: 0 1px 0 #b23e35; |
||||
cursor: pointer; |
||||
vertical-align: top; |
||||
margin: 5px 10px 5px 0px; |
||||
} |
||||
.ajax-file-upload-green { |
||||
background-color: #77b55a; |
||||
-moz-border-radius: 4px; |
||||
-webkit-border-radius: 4px; |
||||
border-radius: 4px; |
||||
margin: 0; |
||||
padding: 0; |
||||
display: inline-block; |
||||
color: #fff; |
||||
font-family: arial; |
||||
font-size: 13px; |
||||
font-weight: normal; |
||||
padding: 4px 15px; |
||||
text-decoration: none; |
||||
cursor: pointer; |
||||
text-shadow: 0 1px 0 #5b8a3c; |
||||
vertical-align: top; |
||||
margin: 5px 10px 5px 0px; |
||||
} |
||||
.ajax-file-upload { |
||||
font-family: Arial, Helvetica, sans-serif; |
||||
font-size: 16px; |
||||
font-weight: bold; |
||||
padding: 15px 20px; |
||||
cursor:pointer; |
||||
line-height:20px; |
||||
height:25px; |
||||
margin:0 10px 10px 0; |
||||
display: inline-block; |
||||
background: #fff; |
||||
border: 1px solid #e8e8e8; |
||||
color: #888; |
||||
text-decoration: none; |
||||
border-radius: 3px; |
||||
-webkit-border-radius: 3px; |
||||
-moz-border-radius: 3px; |
||||
-moz-box-shadow: 0 2px 0 0 #e8e8e8; |
||||
-webkit-box-shadow: 0 2px 0 0 #e8e8e8; |
||||
box-shadow: 0 2px 0 0 #e8e8e8; |
||||
padding: 6px 10px 4px 10px; |
||||
color: #fff; |
||||
background: #2f8ab9; |
||||
border: none; |
||||
-moz-box-shadow: 0 2px 0 0 #13648d; |
||||
-webkit-box-shadow: 0 2px 0 0 #13648d; |
||||
box-shadow: 0 2px 0 0 #13648d; |
||||
vertical-align: middle; |
||||
} |
||||
|
||||
.ajax-file-upload:hover { |
||||
background: #3396c9; |
||||
-moz-box-shadow: 0 2px 0 0 #15719f; |
||||
-webkit-box-shadow: 0 2px 0 0 #15719f; |
||||
box-shadow: 0 2px 0 0 #15719f; |
||||
} |
||||
|
||||
.ajax-upload-dragdrop |
||||
{ |
||||
|
||||
border:2px dotted #A5A5C7; |
||||
width:420px; |
||||
color: #DADCE3; |
||||
text-align:left; |
||||
vertical-align:middle; |
||||
padding:10px 10px 0px 10px; |
||||
} |
||||
|
||||
.state-hover |
||||
{ |
||||
border:2px solid #A5A5C7; |
||||
} |
||||
.ajax-file-upload-container |
||||
{ |
||||
margin:20px 0px 20px 0px; |
||||
} |
@ -0,0 +1,103 @@
@@ -0,0 +1,103 @@
|
||||
<?php |
||||
error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED); |
||||
include_once('./config.php'); |
||||
|
||||
$img_name = $_FILES["file"]["name"]; //文件名称 |
||||
$suffix = substr(strrchr($img_name, '.'), 1);//文件后缀 |
||||
$suffix = strtolower($suffix); //文件后缀转换为小写 |
||||
$rnum = date('dhis',time()).rand(1000,9999); //生成一个随机数 |
||||
//$new_name = substr(md5($img_name.$rnum), 8, 16).'.'.$suffix; //新的文件名 |
||||
$img_type = $_FILES["file"]["type"]; //文件类型 |
||||
$img_size = $_FILES["file"]["size"]; //文件大小 |
||||
$img_tmp = $_FILES["file"]["tmp_name"]; //临时文件名称 |
||||
//生成文件HASH |
||||
$fhash = hash_file("md5",$img_tmp,FALSE); |
||||
$fhash = substr($fhash,8,16); |
||||
//新的文件名 |
||||
$new_name = $fhash.'.'.$suffix; |
||||
$img_error = $_FILES["file"]["error"]; //错误代码 |
||||
$max_size = 2097152; //最大上传大小2M |
||||
$current_time = date('ym',time()); //当前月份 |
||||
$dir = 'uploads/'.$current_time; //图片目录 |
||||
$dir_name = $dir.'/'.$new_name; //完整路径 |
||||
|
||||
//使用exif_imagetype函数来判断文件类型 |
||||
$file_type = exif_imagetype($img_tmp); |
||||
switch ( $file_type ) |
||||
{ |
||||
case IMAGETYPE_GIF: |
||||
$status = 1; |
||||
break; |
||||
case IMAGETYPE_JPEG: |
||||
$status = 1; |
||||
break; |
||||
case IMAGETYPE_PNG: |
||||
$status = 1; |
||||
break; |
||||
case IMAGETYPE_BMP: |
||||
$status = 1; |
||||
break; |
||||
default: |
||||
$status = 0; |
||||
break; |
||||
} |
||||
//判断文件后缀 |
||||
switch ( $suffix ) |
||||
{ |
||||
case jpg: |
||||
$suffix_status = 1; |
||||
break; |
||||
case png: |
||||
$suffix_status = 1; |
||||
break; |
||||
case jpeg: |
||||
$suffix_status = 1; |
||||
break; |
||||
case bmp: |
||||
$suffix_status = 1; |
||||
break; |
||||
case gif: |
||||
$suffix_status = 1; |
||||
break; |
||||
default: |
||||
$suffix_status = 0; |
||||
break; |
||||
} |
||||
//判断文件夹是否存在,不存在则创建目录 |
||||
if(!file_exists($dir)){ |
||||
mkdir($dir,0777,true); |
||||
} |
||||
|
||||
//开始上传 |
||||
if(($img_size <= $max_size) && ($status == 1) && ($suffix_status == 1)) { |
||||
if ($_FILES["file"]["error"] > 0) |
||||
{ |
||||
echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; |
||||
} |
||||
else { |
||||
//如果上传成功 |
||||
if(move_uploaded_file($img_tmp,$dir_name)){ |
||||
//设置自己的TinyPNG API KEY |
||||
// Tinify\setKey("TinyPNG API KEY"); |
||||
//Tinify\fromFile($dir_name)->toFile($dir_name); |
||||
//请在下面设置您自己的域名 |
||||
$img_url = $config['domain'].$dir_name; //自定义图片路径 |
||||
$img_info = getimagesize($dir_name); |
||||
$img_width = $img_info['0']; //图片宽度 |
||||
$img_height = $img_info['1']; //图片高度 |
||||
$re_data = array("linkurl" => $img_url,width => $img_width,"height" => $img_height,"status" => 'ok'); |
||||
//返回json格式 |
||||
echo json_encode($re_data); |
||||
} |
||||
//没有上传成功 |
||||
else{ |
||||
echo md5("360baidu103.jpg"); |
||||
} |
||||
} |
||||
} |
||||
else{ |
||||
$re_data = array("linkurl" => $img_url,width => $img_width,"height" => $img_height,"status" => 'no'); |
||||
//返回json格式 |
||||
echo json_encode($re_data); |
||||
} |
||||
?> |
Loading…
Reference in new issue