choi

upload picture and video

No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -10,6 +10,16 @@ var board = mysql_odbc.init();
var requestIp = require('request-ip');
var videojs = require('video.js')
require('@silvermine/videojs-quality-selector')(videojs);
var multer = require('multer');
var storagepic = multer.diskStorage({ // 2
destination(req, file, cb) {
cb(null, 'assets/img/');
},
filename(req, file, cb) {
cb(null, `${Date.now()}__${file.originalname}`);
},
});
var uploadpic = multer({ storage: storagepic });
// 로그용
var logString;
......@@ -111,7 +121,7 @@ router.get('/write/notice', function(req,res,next){
}
})
router.post('/write/notice', function(req,res,next){
router.post('/write/notice', uploadpic.any(), function(req,res,next){
var ip = requestIp.getClientIp(req);
var nickname = req.user.nickname // var name = req.body.name
var title = req.body.title
......@@ -133,6 +143,31 @@ router.post('/write/notice', function(req,res,next){
if(!idx_) // 글이 없으면 NULL
idx_ = 1;
var piccount=0;
var vidcount=0;
for(var i=0; i<req.files.length;i++){
if(req.files[i].mimetype.slice(0,5) == "image"){
piccount += 1
}
else if(req.files[i].mimetype.slice(0,5) == "video"){
vidcount += 1
}
}
for(var i=0;i<piccount;i++){
var sql_picupload = "insert into picvideo(picname, bulletin_id, boardtitle) values(?,?,'notice');"
var picdata = [req.files.shift().filename, idx_]
board.query(sql_picupload, picdata, function(err,rows) {
if (err) console.error("err : " + err);
})
}
for(var i=0;i<vidcount;i++){
var sql_vidupload = "insert into picvideo(vidname, bulletin_id, boardtitle) values(?,?,'notice');"
var viddata = [req.files.shift().filename, idx_]
board.query(sql_vidupload, viddata, function(err,rows) {
if (err) console.error("err : " + err);
})
}
console.log(logString+req.user.ID+'('+nickname+') 유저가 공지사항 '+idx_+'번 게시글을 작성했습니다.('+ip+')')
res.redirect('/board/read/notice/'+idx_);
});
......@@ -172,7 +207,7 @@ router.get('/read/notice/:idx', function(req,res,next){
var vidarr = []
for(var i=0; i<picvideos.length; i++){
var picadd = "../../../assets/img/" + picvideos[i].picname;
var vidadd = "../../../assets/video/" + picvideos[i].vidname;
var vidadd = "../../../assets/img/" + picvideos[i].vidname;
if(picvideos[i].picname != null){
picarr.push(picadd)
}
......@@ -379,7 +414,7 @@ router.get('/write/composer', function(req,res,next){
}
})
router.post('/write/composer', function(req,res,next){
router.post('/write/composer', uploadpic.any(), function(req,res,next){
var ip = requestIp.getClientIp(req);
var nickname = req.user.nickname // var name = req.body.name
var title = req.body.title
......@@ -401,6 +436,31 @@ router.post('/write/composer', function(req,res,next){
if(!idx_) // 글이 없으면 NULL
idx_ = 1;
var piccount=0;
var vidcount=0;
for(var i=0; i<req.files.length;i++){
if(req.files[i].mimetype.slice(0,5) == "image"){
piccount += 1
}
else if(req.files[i].mimetype.slice(0,5) == "video"){
vidcount += 1
}
}
for(var i=0;i<piccount;i++){
var sql_picupload = "insert into picvideo(picname, bulletin_id, boardtitle) values(?,?,'composer');"
var picdata = [req.files.shift().filename, idx_]
board.query(sql_picupload, picdata, function(err,rows) {
if (err) console.error("err : " + err);
})
}
for(var i=0;i<vidcount;i++){
var sql_vidupload = "insert into picvideo(vidname, bulletin_id, boardtitle) values(?,?,'composer');"
var viddata = [req.files.shift().filename, idx_]
board.query(sql_vidupload, viddata, function(err,rows) {
if (err) console.error("err : " + err);
})
}
console.log(logString+req.user.ID+'('+nickname+') 유저가 작곡가 구인 '+idx_+'번 게시글을 작성했습니다.('+ip+')')
res.redirect('/board/read/composer/'+idx_);
});
......@@ -440,7 +500,7 @@ router.get('/read/composer/:idx', function(req,res,next){
var vidarr = []
for(var i=0; i<picvideos.length; i++){
var picadd = "../../../assets/img/" + picvideos[i].picname;
var vidadd = "../../../assets/video/" + picvideos[i].vidname;
var vidadd = "../../../assets/img/" + picvideos[i].vidname;
if(picvideos[i].picname != null){
picarr.push(picadd)
}
......@@ -647,7 +707,7 @@ router.get('/write/singer', function(req,res,next){
}
})
router.post('/write/singer', function(req,res,next){
router.post('/write/singer', uploadpic.any(), function(req,res,next){
var ip = requestIp.getClientIp(req);
var nickname = req.user.nickname // var name = req.body.name
var title = req.body.title
......@@ -669,6 +729,31 @@ router.post('/write/singer', function(req,res,next){
if(!idx_) // 글이 없으면 NULL
idx_ = 1;
var piccount=0;
var vidcount=0;
for(var i=0; i<req.files.length;i++){
if(req.files[i].mimetype.slice(0,5) == "image"){
piccount += 1
}
else if(req.files[i].mimetype.slice(0,5) == "video"){
vidcount += 1
}
}
for(var i=0;i<piccount;i++){
var sql_picupload = "insert into picvideo(picname, bulletin_id, boardtitle) values(?,?,'singer');"
var picdata = [req.files.shift().filename, idx_]
board.query(sql_picupload, picdata, function(err,rows) {
if (err) console.error("err : " + err);
})
}
for(var i=0;i<vidcount;i++){
var sql_vidupload = "insert into picvideo(vidname, bulletin_id, boardtitle) values(?,?,'singer');"
var viddata = [req.files.shift().filename, idx_]
board.query(sql_vidupload, viddata, function(err,rows) {
if (err) console.error("err : " + err);
})
}
console.log(logString+req.user.ID+'('+nickname+') 유저가 가수 구인 '+idx_+'번 게시글을 작성했습니다.('+ip+')')
res.redirect('/board/read/singer/'+idx_);
});
......@@ -708,7 +793,7 @@ router.get('/read/singer/:idx', function(req,res,next){
var vidarr = []
for(var i=0; i<picvideos.length; i++){
var picadd = "../../../assets/img/" + picvideos[i].picname;
var vidadd = "../../../assets/video/" + picvideos[i].vidname;
var vidadd = "../../../assets/img/" + picvideos[i].vidname;
if(picvideos[i].picname != null){
picarr.push(picadd)
}
......@@ -915,7 +1000,7 @@ router.get('/write/free', function(req,res,next){
}
})
router.post('/write/free', function(req,res,next){
router.post('/write/free', uploadpic.any(), function(req,res,next){
var ip = requestIp.getClientIp(req);
var nickname = req.user.nickname // var name = req.body.name
var title = req.body.title
......@@ -937,6 +1022,31 @@ router.post('/write/free', function(req,res,next){
if(!idx_) // 글이 없으면 NULL
idx_ = 1;
var piccount=0;
var vidcount=0;
for(var i=0; i<req.files.length;i++){
if(req.files[i].mimetype.slice(0,5) == "image"){
piccount += 1
}
else if(req.files[i].mimetype.slice(0,5) == "video"){
vidcount += 1
}
}
for(var i=0;i<piccount;i++){
var sql_picupload = "insert into picvideo(picname, bulletin_id, boardtitle) values(?,?,'free');"
var picdata = [req.files.shift().filename, idx_]
board.query(sql_picupload, picdata, function(err,rows) {
if (err) console.error("err : " + err);
})
}
for(var i=0;i<vidcount;i++){
var sql_vidupload = "insert into picvideo(vidname, bulletin_id, boardtitle) values(?,?,'free');"
var viddata = [req.files.shift().filename, idx_]
board.query(sql_vidupload, viddata, function(err,rows) {
if (err) console.error("err : " + err);
})
}
console.log(logString+req.user.ID+'('+nickname+') 유저가 자유게시판 '+idx_+'번 게시글을 작성했습니다.('+ip+')')
res.redirect('/board/read/free/'+idx_);
});
......@@ -976,7 +1086,7 @@ router.get('/read/free/:idx', function(req,res,next){
var vidarr = []
for(var i=0; i<picvideos.length; i++){
var picadd = "../../../assets/img/" + picvideos[i].picname;
var vidadd = "../../../assets/video/" + picvideos[i].vidname;
var vidadd = "../../../assets/img/" + picvideos[i].vidname;
if(picvideos[i].picname != null){
picarr.push(picadd)
}
......@@ -1183,7 +1293,7 @@ router.get('/write/suggestion', function(req,res,next){
}
})
router.post('/write/suggestion', function(req,res,next){
router.post('/write/suggestion', uploadpic.any(), function(req,res,next){
var ip = requestIp.getClientIp(req);
var nickname = req.user.nickname // var name = req.body.name
var title = req.body.title
......@@ -1205,6 +1315,31 @@ router.post('/write/suggestion', function(req,res,next){
if(!idx_) // 글이 없으면 NULL
idx_ = 1;
var piccount=0;
var vidcount=0;
for(var i=0; i<req.files.length;i++){
if(req.files[i].mimetype.slice(0,5) == "image"){
piccount += 1
}
else if(req.files[i].mimetype.slice(0,5) == "video"){
vidcount += 1
}
}
for(var i=0;i<piccount;i++){
var sql_picupload = "insert into picvideo(picname, bulletin_id, boardtitle) values(?,?,'suggestion');"
var picdata = [req.files.shift().filename, idx_]
board.query(sql_picupload, picdata, function(err,rows) {
if (err) console.error("err : " + err);
})
}
for(var i=0;i<vidcount;i++){
var sql_vidupload = "insert into picvideo(vidname, bulletin_id, boardtitle) values(?,?,'suggestion');"
var viddata = [req.files.shift().filename, idx_]
board.query(sql_vidupload, viddata, function(err,rows) {
if (err) console.error("err : " + err);
})
}
console.log(logString+req.user.ID+'('+nickname+') 유저가 건의사항 '+idx_+'번 게시글을 작성했습니다.('+ip+')')
res.redirect('/board/read/suggestion/'+idx_);
});
......@@ -1244,7 +1379,7 @@ router.get('/read/suggestion/:idx', function(req,res,next){
var vidarr = []
for(var i=0; i<picvideos.length; i++){
var picadd = "../../../assets/img/" + picvideos[i].picname;
var vidadd = "../../../assets/video/" + picvideos[i].vidname;
var vidadd = "../../../assets/img/" + picvideos[i].vidname;
if(picvideos[i].picname != null){
picarr.push(picadd)
}
......
......@@ -10,6 +10,10 @@
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css" />
<!-- Core theme CSS (includes Bootstrap)-->
<link href="/css/styles.css?after" rel="stylesheet" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
</head>
<body>
<!-- Navigation-->
......@@ -54,7 +58,7 @@
<%
}
%>
<form action="/board/write/<%=addr%>" method="post">
<form action="/board/write/<%=addr%>" method="post" enctype="multipart/form-data">
<table border="1">
<tr>
......@@ -68,12 +72,29 @@
<tr>
<td>내용</td>
<td><textarea name="content" id="content" cols="30" rows="10" required></textarea></td>
</tr>
<tr>
<td>
사진 업로드
</td>
<td>
<input type='file' name='uploadpic' id='uploadpic' multiple='multiple' />
</td>
</tr>
<tr>
<td>
동영상 업로드
</td>
<td>
<input type='file' name='uploadpic' id='uploadpic' multiple='multiple' />
</td>
</tr>
<tr>
<td colspan="2">
<button type="submit">글쓰기</button>
</td>
</tr>
</table>
</form>
</div>
......