Browse Source

added database supported (sqlite)

change the way the explore function works.
pull/1/head
git 7 years ago
parent
commit
e83ec1619d
  1. 1
      config.php
  2. 246
      explore.php
  3. 1123
      medoo.php
  4. 17
      upload.php

1
config.php

@ -6,6 +6,7 @@
'admindir' => 'upload', //管理员上传目录,一般保持默认 'admindir' => 'upload', //管理员上传目录,一般保持默认
'username' => 'xiaoz', //管理员账号 'username' => 'xiaoz', //管理员账号
'password' => 'xiaoz.me', //管理员密码 'password' => 'xiaoz.me', //管理员密码
'dbfile' => 'mypic.db',
'tinypng' => '' //使用TinyPNG压缩图片,填写TinyPNG KEY,为空则不启用压缩 'tinypng' => '' //使用TinyPNG压缩图片,填写TinyPNG KEY,为空则不启用压缩
); );
//是否启用腾讯万象优图鉴黄识别 //是否启用腾讯万象优图鉴黄识别

246
explore.php

@ -1,154 +1,94 @@
<?php <?php
error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED); error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED);
//载入配置 //载入配置
include_once('./config.php'); include_once('./config.php');
//载入header //载入header
include_once('./header.php'); include_once('./header.php');
//获取页数
$page = $_GET['page']; // 获得一张随机图片
function randompic() {
$current_time = date('ym',time()); //当前月份 global $config;
include_once("./medoo.php");
$time = $_GET['time']; $db = new medoo([
$mydir = $_GET['dir']; 'database_type' => 'sqlite',
'database_file' => $config['dbfile']
//时间不存在,用当前时间 ]);
if(!isset($time)) { $ret = $db->query("SELECT * FROM pictures ORDER BY RANDOM() LIMIT 1")->fetchAll();
$time = $current_time; if ($ret[0]) {
} return array(
//目录不存在,使用普通用户目录 "id" => $ret[0]['id'],
if(!isset($mydir)) { "showname" => $ret[0]['raw'],
$mydir = $config['userdir']; "url" => $ret[0]['url']
} );
//目录存在,但是既不是用户目录也不是管理员目录 } else
if(($mydir != $config['userdir']) && ($mydir != $config['admindir'])) { return null;
$mydir = $config['userdir']; }
}
//目录存在,并且是管理员目录 $current_time = date('ym',time()); //当前月份
if($mydir == $config['admindir']) {
$mydir = $config['admindir']; $time = $_GET['time'];
//改变下管理员链接地址 $mydir = $_GET['dir'];
$geturl = "&dir=$mydir";
} //时间不存在,用当前时间
//还没有目录 if(!isset($time)) {
if(!file_exists($mydir."/".$time."/")) { $time = $current_time;
//echo $mydir."/".$time."/"; }
echo "<h3 class = 'text-center'>空空如也!</h3>"; //目录不存在,使用普通用户目录
exit; if(!isset($mydir)) {
} $mydir = $config['userdir'];
?> }
<div class="container" style = "margin-top:40px;"> //目录存在,但是既不是用户目录也不是管理员目录
<div class="row"> if(($mydir != $config['userdir']) && ($mydir != $config['admindir'])) {
<div class="col-lg-10 col-md-offset-1"> $mydir = $config['userdir'];
<!--图片预览--> }
<div class="col-lg-6"> //目录存在,并且是管理员目录
<img id = "viewid" src="./static/view.jpg" class="img-thumbnail img-responsive"> if($mydir == $config['admindir']) {
</div> $mydir = $config['admindir'];
<!--图片预览END--> }
<div class="col-lg-6"> $pic="./static/view.jpg";
<table class="table table-striped"> $info=randompic();
<tbody> if ($info)
<?php $pic = $info['url'];
function get_files($dir) { ?>
$files = array(); <div class="container" style = "margin-top:40px;">
<div class="row">
for (; $dir->valid(); $dir->next()) { <div class="col-lg-10 col-md-offset-1">
if ($dir->isDir() && !$dir->isDot()) { <!--图片预览-->
if ($dir->haschildren()) { <div class="text-center">
$files = array_merge($files, get_files($dir->getChildren())); <img id = "viewid" src="<?php echo $pic?>" class="img-thumbnail img-responsive">
}; </div>
}else if($dir->isFile()){ <!--图片预览END-->
$files[] = $dir->getPathName(); </div>
} </div>
} </div>
return $files; <script>
} function view(imgurl) {
$("#viewid").src;
//如果页数不存在或者小于1 $("#viewid").attr('src',imgurl);
if((!isset($page)) || ($page <= 1)) { }
$page = 1; //删除图片
$i = 0; function del(filedir,rowid) {
$num = 15; //行id
} var rowid = 'row' + rowid;
if($page > 1) { //确认删除?
$i = ($page - 1) * 15; var msg = "确认删除?";
$num = $i + 15; if (confirm(msg)==true){
} $.get("./functions.php?type=delete&dir="+filedir,function(data,status){
//删除成功
$path = $mydir.'/'.$time; if(data == 'ok') {
$dir = new RecursiveDirectoryIterator($path); $("#"+rowid).remove();
$fname = get_files($dir); }
$allnum = count($fname) - 1; //文件总数 else{
//echo $allnum; alert(data); //删除失败,弹出报错
//最大页数 }
$allpage = round($allnum / 15,0); });
$uppage = $page - 1; //上一页 }else{
$downpage = $page + 1; //下一页 return false;
}
$downpage = ($page >= $allpage) ? $page : $downpage; }
//echo $allpage; </script>
//如果文件数小于15 <?php
//$num = count($allnum < 15) ? $allnum : $num; //载入页脚
if($allnum <= 15) { include_once('./footer.php');
$num = $allnum;
}
for($i;$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>
<a href="?page=<?php echo $uppage.$geturl; ?>" class = "btn btn-primary"><span class = "glyphicon glyphicon-chevron-left"></span> 上一页</a>
<a href="?page=<?php echo $downpage.$geturl; ?>" class = "btn btn-primary">下一页 <span class = "glyphicon glyphicon-chevron-right"></span></a>
</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');
?> ?>

1123
medoo.php

File diff suppressed because it is too large Load Diff

17
upload.php

@ -89,6 +89,7 @@
$re_data = array("linkurl" => $img_url,width => $img_width,"height" => $img_height,"status" => 'ok'); $re_data = array("linkurl" => $img_url,width => $img_width,"height" => $img_height,"status" => 'ok');
//返回json格式 //返回json格式
echo json_encode($re_data); echo json_encode($re_data);
recordImageInfo($img_name , $dir_name, $img_url);// 记录文件原始名称,文件路径和文件url
exit; exit;
} }
//没有上传成功 //没有上传成功
@ -115,4 +116,20 @@
return $udir; return $udir;
} }
} }
// 记录图片信息并初始化数据库(如果不存在)
function recordImageInfo($rawname, $path, $url) {
global $config;
include_once("./medoo.php");
$db = new medoo([
'database_type' => 'sqlite',
'database_file' => $config['dbfile']
]);
$ret = $db->query("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='pictures'")->fetchAll();
if ($ret[0][0] == 0) {
$db->exec("CREATE TABLE [pictures] ([id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [raw] VARCHAR, [path] VARCHAR, [url] TEXT)");
$db->exec("CREATE INDEX [url] ON [pictures] ([url])");
}
$db->exec("insert into pictures (raw, path, url) values (".$db->pdo->quote($rawname).",\"$path\",\"$url\")");
}
?> ?>
Loading…
Cancel
Save