项目地址:https://github.com/prettyRain/littleAlbumTwo
项目名 littleAlbumTwo
controller : 路由
modles:模块中心
node_modules : 下载的模块(express(封装nodejs)、formidable(上传文件、图片)、silly-datetime)
public : 页面用到的 js css 图片
uploads:存放相册文件夹 文件夹中有图片
views:页面展示
app.js : 控制中心
app.js
/**
* Created by prettyRain on 2018/9/18.
*/
//下载的
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
//自己写的
var route = require('./controller');
//ejs 模板
app.set('view engine','ejs');
//静态页面
app.use(express.static('./public'));
app.use(express.static('./uploads'));
//首页
app.get('/',route.index);
//创建相册
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/addxiangce',route.addxiangce);
app.post('/addxiangce',route.postaddxiangce);
//查看个人相册
app.get('/album/:albumByName',route.albumByName);
//上传图片
app.get('/uppage',route.uppage);
app.post('/uppost',route.uppost);
//展示
app.get('/ablumAll',route.ablumAll);
//删除
app.get('/deletedir',route.deletedir);
//下载图片
app.post('/downphoto',route.downphoto);
app.use("/",route.errorpage);
app.listen(4000);
controller package.json
{
"name": "controller",
"version": "0.0.1",
"main": "route.js"
}
controller route.js
/**
* Created by prettyRain on 2018/9/18.
*/
var file = require('../models/file.js');
var path = require('path');
var fs = require('fs');
/**
* 首页
* @param req
* @param res
* @param next
*/
exports.index = function(req,res,next){
file.index(function(err,arr){
if(err){
next();
return;
}
res.render('index',{
fiels:arr
});
});
}
/**
* 添加相册页面
* @param req
* @param res
* @param next
*/
exports.addxiangce = function(req,res,next){
file.index(function(err,arr){
if(err){
next();
return;
}
res.render('addxiangce',{
fiels:arr
});
});
}
/**
* 添加相册
* @param req
* @param res
* @param next
*/
exports.postaddxiangce = function(req,res,next){
var xcmingchen = req.body.xcmingchen;
file.postaddxiangce(xcmingchen,function(err){
if(err){
next();
return;
}
res.send('success');
});
}
/**
* 展示个人相册
* @param req
* @param res
* @param next
*/
exports.albumByName = function(req,res,next){
var name = req.params.albumByName;
console.log(name);
file.albumByName(name,function(err,files){
if(err){
next();
return;
}
res.render('album',{
fiels:files,
name:name
});
});
}
/**
* 上传图片页面
* @param req
* @param res
* @param next
*/
exports.uppage = function(req,res,next){
file.index(function(err,arr){
if(err){
next();
return;
}
res.render('uppage',{
fiels:arr
});
});
}
/**
* 上传图片
* @param req
* @param res
* @param next
*/
exports.uppost = function(req,res,next){
file.uppost(req,function(err){
if(err && err=="文件太大"){
res.send("文件太大");
}else if(err){
res.send("上传失败");
}else{
res.send("上传成功");
}
})
}
/**
* 展示所有相片
* @param req
* @param res
* @param next
*/
exports.ablumAll = function(req,res,next){
file.ablumAll(function(err,fiels){
if(err){
console.log(err);
next();
return;
}
res.render('ablumAll',{fiels:fiels})
});
}
/**
* 删除文件或文件夹
* @param req
* @param res
* @param next
*/
exports.deletedir = function(req,res,next){
console.log(req.query.arr);
file.deletedir(req.query.arr,function(err){
if(err){
next();
return;
}
res.send('success');
})
}
/**
* 下载图片
* @param req
* @param res
* @param next
*/
exports.downphoto = function(req,res,next){
var arr = req.body.arr;
console.log(arr);
var name = arr;
var photoname = (name).replace(/[^x00-xff]+(\w+.\w+$)/,function(a,b){
return b;
});
var urlpath = path.normalize(__dirname+"/../uploads/"+name);
// 实现文件下载
var filePath = urlpath;
var stats = fs.statSync(filePath);
if(stats.isFile()){
res.set({
'Content-Type': 'application/octet-stream',
'Content-Disposition': 'attachment; filename='+photoname,
'Content-Length': stats.size
});
fs.createReadStream(filePath).pipe(res);
} else {
next();
}
}
/**
* 错误页面
* @param req
* @param res
* @param next
*/
exports.errorpage = function(req,res){
res.render('errPage');
}
models file.js
/**
* Created by prettyRain on 2018/9/18.
*/
var fs = require('fs');
var path = require('path');
var dt = require('silly-datetime');
var formidable = require('formidable');
exports.index = index;
exports.postaddxiangce = postaddxiangce;
exports.albumByName = albumByName;
exports.uppost = uppost;
exports.ablumAll = ablumAll;
exports.deletedir = deletedir;
function index(callback){
fs.readdir('./uploads',function(err,files){
if(err){
callback("错误",null);
return;
}
var arr = [];
(function showdir(i){
if(i == files.length){
callback(null,arr);
//记得要停止
return;
}
fs.stat('./uploads/'+files[i],function(err,stats){
if(err){
callback('错误',null);
return;
}
if(stats.isDirectory()){
arr.push(files[i]);
}
showdir(i+1);
});
})(0);
});
}
function postaddxiangce(name,callback){
fs.mkdir('./uploads/'+name,function(err){
if(err){
callback("错误");
return;
};
callback();
})
}
function albumByName(name,callback){
fs.readdir('./uploads/'+name,function(err,files){
if(err){
callback("错误",null);
return;
}
var arr = [];
(function showfiles(i){
if(files.length == i){
callback(null,arr);
return;
}
fs.stat('./uploads/'+name+"/"+files[i],function(err,stats){
if(err){
callback("错误",null);
return;
}
if(stats.isFile()){
arr.push(files[i]);
}
showfiles(i+1);
});
})(0);
})
}
function uppost(req,callback){
var form = new formidable.IncomingForm()
form.encoding = 'utf-8';
form.uploadDir = "./tempup";
form.parse(req, function(err, fields, files) {
if(err){
callback("错误");
return;
}
var photoname = dt.format(new Date(),'YYYYMMDDHHmmss')+(parseInt(Math.random()*(9999-1000))+1000) + path.extname(files.photo.name);
var newpath = "./uploads/"+fields.albumname+"/"+photoname;
var oldpath = "./"+files.photo.path;
if(files.photo.size > 1024*1024){
fs.unlink(oldpath,function(err){
if(err){
callback("错误");
return;
}
});
callback("文件太大");
return;
}
fs.rename(oldpath,newpath,function(err){
if(err){
console.log(err);
callback("错误");
return;
}
callback();
});
});
}
function ablumAll(callback){
fs.readdir('./uploads',function(err,files){
if(err){
callback("1",null);
return;
}
var arr = [];
(function showarr(i){
if(i == files.length){
callback(null,arr);
return;
}
console.log(i);
fs.stat('./uploads/'+files[i],function(err,stats){
if(err){
console.log(err);
callback("2",null);
return;
}else {
if (stats.isDirectory()) {
fs.readdir('./uploads/' + files[i], function (err, newfiles) {
(function newshow(j) {
if (j == newfiles.length) {
showarr(i + 1);
return;
}
fs.stat('./uploads/' + files[i] + "/" + newfiles[j], function (err, stats) {
if (err) {
callback("3", null);
return;
}
if (stats.isFile()) {
arr.push(files[i] + "/" + newfiles[j]);
}
newshow(j + 1);
});
})(0)
})
} else {
showarr(i + 1);
}
}
});
})(0);
});
}
function deletedir(arr,callback){
(function listarr(k){
if(arr.length == k){
callback();
return;
}
fs.stat("./uploads/"+arr[k],function(err,stats){
if(stats.isDirectory()){
fs.readdir('./uploads/'+arr[k],function(err,files){
(function deletefile(i){
if(i == files.length){
fs.rmdir('./uploads/'+arr[k],function(err){
if(err){
callback("1");
}
})
listarr(k+1);
return;
}
fs.unlink('./uploads/'+arr[k]+'/'+files[i],function(err){
if(err){
callback("2");
}
deletefile(i+1);
});
})(0)
});
}else if(stats.isFile()){
fs.unlink('./uploads/'+arr[k],function(err){
if(err){
callback('3');
return;
}
listarr(k+1);
});
}
})
})(0);
}
public bootstrap
public images
public newtip.css
.tip {
text-align:center;
line-height:30px;
animation:mymove .8s forwards;
z-index:10000;
position:fixed;
top:-20px;
left:50%;
margin-left:-50px;
min-width:100px;
height:30px;
padding:0 5px;
border-radius:15px;
background-image:linear-gradient(135deg,yellow 25%,#ffba44 25%,#ffba44 50%,yellow 50%,yellow 75%,#ffba44 75%,#ffba44 100% );
background-size:30px 30px;
background-position:0 0;
background-repeat:repeat-x;
}
@keyframes mymove {
from{
transform:translateY(0);
}
to{
transform:translateY(200px);
}
}
public newtip.js 弹出框
/**
* 弹出框
* Created by prettyRain on 2018/9/18.
*/
function alerttip(){
var timer ;
return function(content){
window.clearTimeout(timer);
timer = window.setTimeout(function(){
$('body').append("<div class='tip'>"+content+"</div>");
window.setTimeout(function(){
$('.tip').remove();
},1500)
},1000)
}
}
views index.ejs 首页
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>小小相册</title>
<!-- Bootstrap core CSS -->
<link href="/bootstrap/css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="/newtip.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container" style="box-sizing:border-box">
<nav class="navbar navbar-inverse navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">小小相册</a>
</div>
<div id="navbar" class="navbar-collapse collapse" aria-expanded="false" style="height: 1px;">
<ul class="nav navbar-nav">
<li><a href="/addxiangce">添加相册</a></li>
<li><a href="/uppage">上传</a></li>
<li><a href="/ablumAll">展示</a></li>
<li><a href="javascript:deletedir()">删除</a></li>
</ul>
</div>
</div>
</nav>
<div class="jumbotron">
<div class="row">
<%for(var i in fiels){%>
<div class="col-xs-6 col-md-3">
<a href="/album/<%=fiels[i]%>" class="thumbnail">
<img src="/images/xiangche.jpg" alt="...">
</a>
<p style="text-align:center;font-size:14px;"><input type="checkbox" name="dir" value="<%=fiels[i]%>"><%=fiels[i]%></p>
</div>
<%}%>
</div>
</div>
</div> <!-- /container -->
<div class="modal fade" tabindex="-1" role="dialog" id="myInput">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">提示</h4>
</div>
<div class="modal-body">
<p>确认删除吗?…</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary isdelete">确定</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="/bootstrap/js/bootstrap.min.js"></script>
<script src="/newtip.js" type="text/javascript"></script>
<script>
var arr = [];
function deletedir(){
arr = [];
$('input[name=dir]:checked').each(function(index,item){
console.log(index,item);
arr.push(item.value);
})
if(arr.length>0){
$('#myInput').modal('show')
}
}
$('.isdelete').on('click',function(){
$('#myInput').modal('hide');
$.get('/deletedir',{arr:arr},function(data){
if(data=='success'){
window.location.href='/'
}
})
})
</script>
</body>
</html>
views addxiangce.ejs 添加相册
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>小小相册</title>
<!-- Bootstrap core CSS -->
<link href="/bootstrap/css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="/newtip.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<nav class="navbar navbar-inverse navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">小小相册</a>
</div>
<div id="navbar" class="navbar-collapse collapse" aria-expanded="false" style="height: 1px;">
<ul class="nav navbar-nav">
<li><a class="active" href="/addxiangce">添加相册</a></li>
<li><a href="/uppage">上传</a></li>
<li><a href="/ablumAll">展示</a></li>
<li><a href="#contact">删除</a></li>
</ul>
</div>
</div>
</nav>
<%for(var i in fiels){%>
<input type="hidden" class="xcmingchen" value="<%=fiels[i]%>">
<%}%>
<div class="jumbotron">
<form method="post" action="./addxiangce">
<div class="form-group">
<label for="exampleInputFile">相册名称</label>
<input type="text" id="exampleInputFile" class="form-control" name="xcmingchen">
</div>
<button type="botton" class="btn btn-default">提交</button>
</form>
</div>
</div> <!-- /container -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="/bootstrap/js/bootstrap.min.js"></script>
<script src="/newtip.js" type="text/javascript"></script>
<script>
var tip = alerttip();
var xcmingchenarr = [];
$('.xcmingchen').each(function(index,item){
xcmingchenarr.push($(this).val());
})
function requireform(){
if(!$('input[name=xcmingchen]').val()){
tip('相册名称不能为空');
return false;
}else if(xcmingchenarr.join('-').indexOf($('input[name=xcmingchen]')) != -1 ){
tip('相册名称已被占用');
return false;
}
return true;
}
$('.btn-default').on('click',function(){
console.log(xcmingchenarr.join('-')+"=="+$('input[name=xcmingchen]'));
if(!$('input[name=xcmingchen]').val()){
tip('相册名称不能为空');
return false;
}else if(xcmingchenarr.join('-').indexOf($('input[name=xcmingchen]').val()) != -1 ){
tip('相册名称已被占用');
return false;
}
$.post('/addxiangce',{xcmingchen:$('#exampleInputFile').val()},function(data){
console.log(data);
window.location.href='/';
});
})
</script>
</body>
</html>
views album.ejs 展示个人相册
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>小小相册</title>
<!-- Bootstrap core CSS -->
<link href="/bootstrap/css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="/newtip.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container" style="box-sizing:border-box">
<nav class="navbar navbar-inverse navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">小小相册</a>
</div>
<div id="navbar" class="navbar-collapse collapse" aria-expanded="false" style="height: 1px;">
<ul class="nav navbar-nav">
<li><a href="/addxiangce">添加相册</a></li>
<li><a href="/uppage">上传</a></li>
<li><a href="/ablumAll">展示</a></li>
<li><a href="javascript:deletedir();">删除</a></li>
<li><a href="javascript:download();">下载图片(只能选一张)</a></li>
</ul>
</div>
</div>
</nav>
<div class="jumbotron">
<div class="row">
<%for(var i in fiels){%>
<div class="col-xs-6 col-md-3">
<a href="/<%=name%>/<%=fiels[i]%>" class="thumbnail">
<img src="/<%=name%>/<%=fiels[i]%>" alt="...">
</a>
<p style="text-align:center;font-size:14px;"><input type="checkbox" name="dir" value="<%=name%>/<%=fiels[i]%>"><%=fiels[i]%>></p>
</div>
<%}%>
</div>
</div>
</div> <!-- /container -->
<div class="modal fade" tabindex="-1" role="dialog" id="myInput">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">提示</h4>
</div>
<div class="modal-body">
<p>确认删除吗?…</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary isdelete">确定</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="/bootstrap/js/bootstrap.min.js"></script>
<script src="/newtip.js" type="text/javascript"></script>
<script>
var arr = [];
function deletedir(){
arr = [];
$('input[name=dir]:checked').each(function(index,item){
arr.push(item.value);
})
if(arr.length>0){
$('#myInput').modal('show')
}
}
$('.isdelete').on('click',function(){
$('#myInput').modal('hide');
$.get('/deletedir',{arr:arr},function(data){
if(data=='success'){
window.location.href='/album/'+ '<%=name%>'
}
})
})
function download(){
$('.formclazz').remove();
$('input[name=dir]:checked').each(function(index,item){
$('body').append('<form action="/downphoto" method="post" class="formclazz '+index+'a"> </form>');
$('.'+index+'a').append($('<input type="hidden" name="arr" value="'+item.value+'">'));
})
$('.formclazz').submit();
}
</script>
</body>
</html>
views uppage.ejs 上传照片
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>小小相册</title>
<!-- Bootstrap core CSS -->
<link href="/bootstrap/css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="/newtip.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container" style="box-sizing:border-box">
<nav class="navbar navbar-inverse navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">小小相册</a>
</div>
<div id="navbar" class="navbar-collapse collapse" aria-expanded="false" style="height: 1px;">
<ul class="nav navbar-nav">
<li><a href="/addxiangce">添加相册</a></li>
<li><a href="/uppage">上传</a></li>
<li><a href="/ablumAll">展示</a></li>
<li><a href="#contact">删除</a></li>
</ul>
</div>
</div>
</nav>
<div class="jumbotron">
<div class="row">
<form action="/uppost" method="post" enctype="multipart/form-data" onsubmit="return requireform()">
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<select name="albumname" id="" class="form-control">
<%for(var i in fiels){%>
<option value="<%=fiels[i]%>"><%=fiels[i]%></option>
<%}%>
</select>
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<input type="file" id="exampleInputFile" accept="image/*" name="photo">
</div>
<button type="submit" class="btn btn-default">提交</button>
</form>
</div>
</div>
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="/bootstrap/js/bootstrap.min.js"></script>
<script src="/newtip.js" type="text/javascript"></script>
<script>
var tip = alerttip();
function requireform(){
if(!$('input[name=photo]').val()){
tip('请选择图片');
return false;
}
return true;
}
</script>
</body>
</html>
views ablumAll.ejs 展示所有相片
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>小小相册</title>
<!-- Bootstrap core CSS -->
<link href="/bootstrap/css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" href="/newtip.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container" style="box-sizing:border-box">
<nav class="navbar navbar-inverse navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">小小相册</a>
</div>
<div id="navbar" class="navbar-collapse collapse" aria-expanded="false" style="height: 1px;">
<ul class="nav navbar-nav">
<li><a href="/addxiangce">添加相册</a></li>
<li><a href="/uppage">上传</a></li>
<li><a href="/ablumAll">展示</a></li>
<li><a href="javascript:deletedir();">删除</a></li>
</ul>
</div>
</div>
</nav>
<div class="jumbotron">
<div class="row">
<%for(var i in fiels){%>
<div class="col-xs-6 col-md-3">
<a href="/<%=fiels[i]%>" class="thumbnail">
<img src="/<%=fiels[i]%>" alt="...">
</a>
<p style="text-align:center;font-size:14px;"><input type="checkbox" name="dir" value="<%=fiels[i]%>"><%=fiels[i]%></p>
</div>
<%}%>
</div>
</div>
</div> <!-- /container -->
<div class="modal fade" tabindex="-1" role="dialog" id="myInput">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">提示</h4>
</div>
<div class="modal-body">
<p>确认删除吗?…</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary isdelete">确定</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="/bootstrap/js/bootstrap.min.js"></script>
<script src="/newtip.js" type="text/javascript"></script>
<script>
var arr = [];
function deletedir(){
arr = [];
$('input[name=dir]:checked').each(function(index,item){
console.log(index,item);
arr.push(item.value);
})
if(arr.length>0){
$('#myInput').modal('show')
}
}
$('.isdelete').on('click',function(){
$('#myInput').modal('hide');
$.get('/deletedir',{arr:arr},function(data){
if(data=='success'){
window.location.href='/ablumAll'
}
})
})
</script>
</body>
</html>
views errPage.ejs 错误页面
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>小小相册</title>
<!-- Bootstrap core CSS -->
<link href="/bootstrap/css/bootstrap.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<!-- Static navbar -->
<nav class="navbar navbar-inverse navbar-static-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">小小相册</a>
</div>
<div id="navbar" class="navbar-collapse collapse" aria-expanded="false" style="height: 1px;">
<ul class="nav navbar-nav">
<li><a href="/addxiangce">添加相册</a></li>
<li><a href="/uppage">上传</a></li>
<li><a href="/ablumAll">展示</a></li>
</ul>
</div>
</div>
</nav>
<div class="jumbotron">
<image src="/images/errPage.gif" style="width:100%;"></image>
</div>
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script src="/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>