Browse Source

1.0

pull/1/head
xiaoz 7 years ago
parent
commit
504e226128
  1. 26
      README.md
  2. 26
      about.php
  3. 9
      config.php
  4. 116
      explore.php
  5. 12
      footer.php
  6. 76
      functions.php
  7. 70
      header.php
  8. 55
      index.php
  9. 52
      login.php
  10. 21
      pro.php
  11. 1
      static/embed.js
  12. 16
      static/style.css
  13. BIN
      static/view.jpg
  14. 18
      upload.php

26
README.md

@ -1,2 +1,24 @@ @@ -1,2 +1,24 @@
# imgurl
继XZ Pic后,xiaoz的又一款图床程序。
# ImgURL
ImgURL是一个简单、纯粹的图床程序,使用PHP脚本开发,不需要数据库支持,也没有复杂的配置。
### 环境要求
* PHP >= 5.6
* 需要exif函数支持
### 开发计划
- [x] 图片上传与预览
- [x] 一键生成链接
- [x] 浏览与删除图片
- [ ] 图片压缩
- [ ] 多图上传
- [ ] 图片鉴黄
### 安装
<p>访问:<a href="https://github.com/helloxz/imgurl/archive/master.zip" target = "_blank" rel = "nofollow">master.zip</a>下载最新版ImgURL程序,放到您的站点根目录并解压。修改一下<code>config.php</code>设置你自己的域名和密码,访问<code>http(s)://domain.com/</code>即可,就是这么简单。</p>
### 部分截图
![](https://i.bk.tn/uploads/1712/230615302734.png)
### 联系我
* Blog:<a href = "https://www.xiaoz.me/" target = "_blank">https://www.xiaoz.me/</a>
* <li>QQ:337003006</li>

26
about.php

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
<?php
include_once('header.php');
?>
<div class="container" style = "margin-top:40px;">
<div class="row">
<div class="col-lg-10 col-md-offset-1">
<h1>ImgURL</h1>
<p>ImgURL是一个干尽、纯粹的图床程序,使用PHP脚本开发,不需要数据库支持,也没有复杂的配置。</p>
<p>没有免费的午餐,也没用永久免费的图床,ImgURL无法保障永久存储您的图片,但ImgURL让图床多了一个选择,只有图片掌握在自己手中才更安全。</p>
<h3>安装</h3>
<p>访问:<a href="https://github.com/helloxz/imgurl/archive/master.zip" target = "_blank" rel = "nofollow">master.zip</a>下载最新版ImgURL程序,放到您的站点根目录并解压。修改一下<code>config.php</code>设置你自己的域名和密码,访问<code>http(s)://domain.com/</code>即可,就是这么简单。</p>
<h3>说明</h3>
<p><code>imgurl.org</code>也可以上传图片,但ImgURL的目的是提供私人图床程序,<code>imgurl.org</code>仅作为演示使用,游客上传的图片随时可能被删除,因此推荐您下载ImgURL自行部署。</p>
<p>ImgURL是一个开源免费的个人项目,请勿将ImgURL用于商业用途,未经授权也不要去除底部版权。</p>
<p><b>项目地址:</b><a href = "https://github.com/helloxz/imgurl" target = "_blank" rel = "nofollow">https://github.com/helloxz/imgurl</a></p>
<h3>联系我</h3>
<ul>
<li>Blog:<a href = "https://www.xiaoz.me/" target = "_blank">https://www.xiaoz.me/</a></li>
<li>QQ:337003006</li>
</ul>
</div>
</div>
</div>
<?php
include_once('footer.php');
?>

9
config.php

@ -1,6 +1,11 @@ @@ -1,6 +1,11 @@
<?php
$config = array(
'domain' => 'http://localhost/imgurl/',
'watermark' => 'false'
'domain' => 'http://localhost/imgurl/', //网站域名
'watermark' => 'false', //文字水印
'userdir' => 'temp', //访客上传目录,一般保持默认
'admindir' => 'upload', //管理员上传目录,一般保持默认
'username' => 'xiaoz', //管理员账号
'password' => 'xiaoz.me', //管理员密码
'tinypng' => '' //使用TinyPNG压缩图片
);
?>

116
explore.php

@ -0,0 +1,116 @@ @@ -0,0 +1,116 @@
<?php
error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED);
//载入配置
include_once('./config.php');
//载入header
include_once('./header.php');
$current_time = date('ym',time()); //当前月份
$time = $_GET['time'];
$mydir = $_GET['dir'];
//时间不存在,用当前时间
if(!isset($time)) {
$time = $current_time;
}
//目录不存在,使用普通用户目录
if(!isset($mydir)) {
$mydir = $config['userdir'];
}
//目录存在,但是既不是用户目录也不是管理员目录
if(($mydir != $config['userdir']) && ($mydir != $config['admindir'])) {
$mydir = $config['userdir'];
}
//目录存在,并且是管理员目录
if($mydir == $config['admindir']) {
$mydir = $config['admindir'];
}
?>
<div class="container" style = "margin-top:40px;">
<div class="row">
<div class="col-lg-10 col-md-offset-1">
<!--图片预览-->
<div class="col-lg-6">
<img id = "viewid" src="./static/view.jpg" class="img-thumbnail img-responsive">
</div>
<!--图片预览END-->
<div class="col-lg-6">
<table class="table table-striped">
<tbody>
<?php
function get_files($dir) {
$files = array();
for (; $dir->valid(); $dir->next()) {
if ($dir->isDir() && !$dir->isDot()) {
if ($dir->haschildren()) {
$files = array_merge($files, get_files($dir->getChildren()));
};
}else if($dir->isFile()){
$files[] = $dir->getPathName();
}
}
return $files;
}
$path = $mydir.'/'.$time;
$dir = new RecursiveDirectoryIterator($path);
$fname = get_files($dir);
$num = count($fname) - 1;
for($i = 0;$i <= $num;$i++) {
$fname[$i] = str_replace("\\","/",$fname[$i]);
//如果文件是空的,则终止循环
?>
<tr id = "row<?php echo $i; ?>">
<td onmouseover = "return view('<?php echo $config['domain'].$fname[$i] ?>');">
<?php
echo "<a href = "."'".$config['domain'].$fname[$i]."' target = '_blank'>"."$fname[$i]</a>";
?>
</td>
<td>
<?php
if(isset($_COOKIE['uid'])) {
echo "<a href = \"javascript:;\" onclick = \"del('$fname[$i]',$i);\">删除</a>";
}
?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
function view(imgurl) {
$("#viewid").src;
$("#viewid").attr('src',imgurl);
}
//删除图片
function del(filedir,rowid) {
//行id
var rowid = 'row' + rowid;
//确认删除?
var msg = "确认删除?";
if (confirm(msg)==true){
$.get("./functions.php?type=delete&dir="+filedir,function(data,status){
//删除成功
if(data == 'ok') {
$("#"+rowid).remove();
}
else{
alert(data); //删除失败,弹出报错
}
});
}else{
return false;
}
}
</script>
<?php
//载入页脚
include_once('./footer.php');
?>

12
footer.php

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
<!--页脚-->
<div id = "footer">
<div class="container">
<div class="row">
<!--这是一个开源免费的作品,请为她保留版权-->
<div class="col-lg-10 col-md-offset-1">Copyright Ⓒ 2017 Powered by <a href="https://github.com/helloxz/imgurl" title = "ImgURL" target = "_blank" rel = "nofollow">ImgURL</a>. Author: <a href="https://www.xiaoz.me/" title = "小z博客" target = "_blank">xiaoz.me</a>. 请勿上传违反中国大陆法律的图片,违者后果自负。</div>
</div>
</div>
</div>
</body>
</html>

76
functions.php

@ -0,0 +1,76 @@ @@ -0,0 +1,76 @@
<?php
error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED);
include_once('./config.php');
$type = $_GET['type']; //获取方法类型
$user = $_POST['user']; //用户名
$pass = $_POST['pass']; //密码
$imgname = $_GET['dir']; //获取图片路径
//用户ID
$userid = md5($config['username'].$config['password']);
//登录ID
$loginid = md5($user.$pass);
//方法判断
switch($type) {
case 'login':
login($userid,$loginid);
break;
case 'logout':
logout();
case 'delete':
$uid = $_COOKIE['uid'];
$loginid = md5($config['username'].$config['password']);
if($loginid == $uid) {
delete($imgname,$config['userdir'],$config['admindir']);
}
else{
echo '请先登录';
}
break;
default:
echo '错误的请求!';
exit;
}
//登录方法
function login($userid,$loginid) {
if($userid == $loginid) {
echo 'ok';
//设置Cookie,保存7天
setcookie(uid, $userid, time()+604800);
exit;
}
else {
echo 'no';
exit;
}
}
//退出
function logout(){
setcookie(uid, "", time() - 3600);
echo '已退出';
header("Location: ./index.php");
exit;
}
//删除
function delete($imgname,$userdir,$admindir) {
//字符串分割
$imgdir = explode("/",$imgname);
//只允许删除用户目录和管理员目录
if(($imgdir[0] == $userdir) || ($imgdir[0] == $admindir)){
if(unlink($imgname)) {
echo 'ok'; //删除图片成功
}
else {
echo '删除失败,可能是图片不存在。';
}
}
else {
echo '非法操作';
exit;
}
}
?>

70
header.php

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>ImgURL - 简单、纯粹的图床程序。</title>
<meta name="generator" content="EverEdit" />
<meta name="author" content="xiaoz.me" />
<meta name="keywords" content="ImgURL,免费图床,图床程序,小z图床,XZ Pic" />
<meta name="description" content="ImgURL是一个简单、纯粹的图床程序,让个人图床多一个选择。" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<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 = "./static/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-10 col-md-offset-1">
<nav class="navbar navbar-inverse" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse"
data-target="#example-navbar-collapse">
<span class="sr-only">切换导航</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="./index.php">ImgURL</a>
</div>
<div class="collapse navbar-collapse" id="example-navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="./explore.php">探索发现</a></li>
<li><a href="./pro.php">捐赠版</a></li>
<li><a href="./about.php">关于</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<?php
if(isset($_COOKIE['uid'])) {
include_once('./config.php');
$mydir = $config['admindir'];
echo "<li><a href='./explore.php?dir=$mydir'>管理员</a></li>";
echo " | ";
echo "<li><a href='./functions.php?type=logout'>退出</a></li>";
}
else {
echo "<li><a href='./login.php'>登录</a></li>";
}
?>
</ul>
</div>
</div>
</nav>
</div>
</div>
</div>
</div>
<!--导航栏END-->

55
index.php

@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
<?php
//载入header
include_once('./header.php');
?>
<div style = "clear:both;"></div>
<div class="container" style = "margin-bottom:40px;">
<div class="row">
<div class="col-lg-10 col-md-offset-1">
<div id="fileuploader">Upload</div>
</div>
</div>
</div>
<!--上传成功后-->
<div class="container" style = "margin-bottom:40px;">
<div class="row">
<div class="col-lg-10 col-md-offset-1">
<!--显示-->
<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>
<!--上传成功END-->
<?php
//载入页脚
include_once('./footer.php');
?>

52
login.php

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
<?php
//载入header
include_once('./header.php');
?>
<!--登录页面-->
<div class="container" style = "margin-top:40px;">
<div class="row">
<div class="col-lg-6 col-md-offset-3">
<form class="form-horizontal" role="form" method = "post">
<div class="form-group">
<label class="col-sm-2 control-label">用户名</label>
<div class="col-sm-10">
<input type="text" class="form-control" id = "user">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">密 码</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="pass">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-default" id = "login">登 录</button> <label for="" id = "loading" style = "color:#3E9827;display:none;">注册中...</label>
</div>
</div>
</form>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$("#login").click(function(){
var user = $("#user").val();
var pass = $("#pass").val();
$.post("./functions.php?type=login",{user:user,pass:pass},function(data,status){
if(data == 'ok') {
window.location.href = "./index.php";
}
else{
alert('用户名或密码不对');
}
});
});
});
</script>
<!--登录页面end-->
<?php
//载入页脚
include_once('./footer.php');
?>

21
pro.php

@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
<?php
include_once('header.php');
?>
<div class="container" style = "margin-top:40px;">
<div class="row">
<div class="col-lg-10 col-md-offset-1">
<h1>捐赠版</h1>
<p>ImgURL普通版和捐赠版功能上没有任何区别,不过您可以请作者喝一杯咖啡或吃一顿午餐即可获得捐赠版。可扫描下方二维码获取,留言请填写自己的网址。</p>
<p><img src="https://cdn.xiaoz.me/wp-content/uploads/2013/12/juanzeng260.png" alt="" width="260" height="309" class="alignnone size-full wp-image-9144" /></p>
<h3>技术支持</h3>
<p>获得捐赠版的童鞋,可以去除底部版权,可提供首次安装及调试。(但不提供代码再次开发)</p>
<ul>
<li>Blog:<a href = "https://www.xiaoz.me/" target = "_blank">https://www.xiaoz.me/</a></li>
<li>QQ:337003006</li>
</ul>
</div>
</div>
</div>
<?php
include_once('footer.php');
?>

1
static/embed.js

@ -44,3 +44,4 @@ function copy(url) { @@ -44,3 +44,4 @@ function copy(url) {
}
});
}

16
static/style.css

@ -1,13 +1,15 @@ @@ -1,13 +1,15 @@
.ajax-file-upload-container {
display: none;
}
.ajax-upload-dragdrop{
#fileuploader {
width:100%;
}
.ajax-upload-dragdrop {
height:200px;
}
#fileuploader {
/*width:100%;*/
}
.ajax-file-upload {
margin-left:auto;
margin-right:auto;
@ -19,6 +21,7 @@ @@ -19,6 +21,7 @@
display:none;
width:100%;
position:fixed;
clear:both;
}
#fileuploader {
margin-top:10%;
@ -26,6 +29,7 @@ @@ -26,6 +29,7 @@
#relink{
display: none;
margin-top:36px;
width:100%;
}
#relink lable{
color:#2BD5AA;
@ -39,6 +43,7 @@ @@ -39,6 +43,7 @@
display: none;
z-index: 100;
top:60px;
clear:both;
}
.msg{
color:green;
@ -62,8 +67,11 @@ @@ -62,8 +67,11 @@
}
#menu .navbar {
margin-bottom:0;
border-left:0;
border-right:0;
}
#footer{
width:100%;
background-color: #F5F5F5;

BIN
static/view.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

18
upload.php

@ -2,6 +2,9 @@ @@ -2,6 +2,9 @@
error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED);
include_once('./config.php');
$dir = check($_COOKIE['uid'],$config['username'],$config['password'],$config['userdir'],$config['admindir']);
$img_name = $_FILES["file"]["name"]; //文件名称
$suffix = substr(strrchr($img_name, '.'), 1);//文件后缀
$suffix = strtolower($suffix); //文件后缀转换为小写
@ -18,7 +21,7 @@ @@ -18,7 +21,7 @@
$img_error = $_FILES["file"]["error"]; //错误代码
$max_size = 2097152; //最大上传大小2M
$current_time = date('ym',time()); //当前月份
$dir = 'uploads/'.$current_time; //图片目录
$dir = $dir.'/'.$current_time; //图片目录
$dir_name = $dir.'/'.$new_name; //完整路径
//使用exif_imagetype函数来判断文件类型
@ -100,4 +103,17 @@ @@ -100,4 +103,17 @@
//返回json格式
echo json_encode($re_data);
}
//判断用户是否登录,5个参数,cookie,用户名、密码、用户上传目录、管理员上传目录
function check($cookie,$user,$pass,$udir,$adir){
$loginid = $cookie;
$userid = md5($user.$pass);
if($loginid == $userid) {
return $adir;
}
else {
return $udir;
}
}
?>
Loading…
Cancel
Save