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(); ...@@ -10,6 +10,16 @@ var board = mysql_odbc.init();
10 var requestIp = require('request-ip'); 10 var requestIp = require('request-ip');
11 var videojs = require('video.js') 11 var videojs = require('video.js')
12 require('@silvermine/videojs-quality-selector')(videojs); 12 require('@silvermine/videojs-quality-selector')(videojs);
13 +var multer = require('multer');
14 +var storagepic = multer.diskStorage({ // 2
15 + destination(req, file, cb) {
16 + cb(null, 'assets/img/');
17 + },
18 + filename(req, file, cb) {
19 + cb(null, `${Date.now()}__${file.originalname}`);
20 + },
21 + });
22 +var uploadpic = multer({ storage: storagepic });
13 23
14 // 로그용 24 // 로그용
15 var logString; 25 var logString;
...@@ -111,7 +121,7 @@ router.get('/write/notice', function(req,res,next){ ...@@ -111,7 +121,7 @@ router.get('/write/notice', function(req,res,next){
111 } 121 }
112 }) 122 })
113 123
114 -router.post('/write/notice', function(req,res,next){ 124 +router.post('/write/notice', uploadpic.any(), function(req,res,next){
115 var ip = requestIp.getClientIp(req); 125 var ip = requestIp.getClientIp(req);
116 var nickname = req.user.nickname // var name = req.body.name 126 var nickname = req.user.nickname // var name = req.body.name
117 var title = req.body.title 127 var title = req.body.title
...@@ -133,6 +143,31 @@ router.post('/write/notice', function(req,res,next){ ...@@ -133,6 +143,31 @@ router.post('/write/notice', function(req,res,next){
133 if(!idx_) // 글이 없으면 NULL 143 if(!idx_) // 글이 없으면 NULL
134 idx_ = 1; 144 idx_ = 1;
135 145
146 + var piccount=0;
147 + var vidcount=0;
148 + for(var i=0; i<req.files.length;i++){
149 + if(req.files[i].mimetype.slice(0,5) == "image"){
150 + piccount += 1
151 + }
152 + else if(req.files[i].mimetype.slice(0,5) == "video"){
153 + vidcount += 1
154 + }
155 + }
156 + for(var i=0;i<piccount;i++){
157 + var sql_picupload = "insert into picvideo(picname, bulletin_id, boardtitle) values(?,?,'notice');"
158 + var picdata = [req.files.shift().filename, idx_]
159 + board.query(sql_picupload, picdata, function(err,rows) {
160 + if (err) console.error("err : " + err);
161 + })
162 + }
163 + for(var i=0;i<vidcount;i++){
164 + var sql_vidupload = "insert into picvideo(vidname, bulletin_id, boardtitle) values(?,?,'notice');"
165 + var viddata = [req.files.shift().filename, idx_]
166 + board.query(sql_vidupload, viddata, function(err,rows) {
167 + if (err) console.error("err : " + err);
168 + })
169 + }
170 +
136 console.log(logString+req.user.ID+'('+nickname+') 유저가 공지사항 '+idx_+'번 게시글을 작성했습니다.('+ip+')') 171 console.log(logString+req.user.ID+'('+nickname+') 유저가 공지사항 '+idx_+'번 게시글을 작성했습니다.('+ip+')')
137 res.redirect('/board/read/notice/'+idx_); 172 res.redirect('/board/read/notice/'+idx_);
138 }); 173 });
...@@ -172,7 +207,7 @@ router.get('/read/notice/:idx', function(req,res,next){ ...@@ -172,7 +207,7 @@ router.get('/read/notice/:idx', function(req,res,next){
172 var vidarr = [] 207 var vidarr = []
173 for(var i=0; i<picvideos.length; i++){ 208 for(var i=0; i<picvideos.length; i++){
174 var picadd = "../../../assets/img/" + picvideos[i].picname; 209 var picadd = "../../../assets/img/" + picvideos[i].picname;
175 - var vidadd = "../../../assets/video/" + picvideos[i].vidname; 210 + var vidadd = "../../../assets/img/" + picvideos[i].vidname;
176 if(picvideos[i].picname != null){ 211 if(picvideos[i].picname != null){
177 picarr.push(picadd) 212 picarr.push(picadd)
178 } 213 }
...@@ -379,7 +414,7 @@ router.get('/write/composer', function(req,res,next){ ...@@ -379,7 +414,7 @@ router.get('/write/composer', function(req,res,next){
379 } 414 }
380 }) 415 })
381 416
382 -router.post('/write/composer', function(req,res,next){ 417 +router.post('/write/composer', uploadpic.any(), function(req,res,next){
383 var ip = requestIp.getClientIp(req); 418 var ip = requestIp.getClientIp(req);
384 var nickname = req.user.nickname // var name = req.body.name 419 var nickname = req.user.nickname // var name = req.body.name
385 var title = req.body.title 420 var title = req.body.title
...@@ -401,6 +436,31 @@ router.post('/write/composer', function(req,res,next){ ...@@ -401,6 +436,31 @@ router.post('/write/composer', function(req,res,next){
401 if(!idx_) // 글이 없으면 NULL 436 if(!idx_) // 글이 없으면 NULL
402 idx_ = 1; 437 idx_ = 1;
403 438
439 + var piccount=0;
440 + var vidcount=0;
441 + for(var i=0; i<req.files.length;i++){
442 + if(req.files[i].mimetype.slice(0,5) == "image"){
443 + piccount += 1
444 + }
445 + else if(req.files[i].mimetype.slice(0,5) == "video"){
446 + vidcount += 1
447 + }
448 + }
449 + for(var i=0;i<piccount;i++){
450 + var sql_picupload = "insert into picvideo(picname, bulletin_id, boardtitle) values(?,?,'composer');"
451 + var picdata = [req.files.shift().filename, idx_]
452 + board.query(sql_picupload, picdata, function(err,rows) {
453 + if (err) console.error("err : " + err);
454 + })
455 + }
456 + for(var i=0;i<vidcount;i++){
457 + var sql_vidupload = "insert into picvideo(vidname, bulletin_id, boardtitle) values(?,?,'composer');"
458 + var viddata = [req.files.shift().filename, idx_]
459 + board.query(sql_vidupload, viddata, function(err,rows) {
460 + if (err) console.error("err : " + err);
461 + })
462 + }
463 +
404 console.log(logString+req.user.ID+'('+nickname+') 유저가 작곡가 구인 '+idx_+'번 게시글을 작성했습니다.('+ip+')') 464 console.log(logString+req.user.ID+'('+nickname+') 유저가 작곡가 구인 '+idx_+'번 게시글을 작성했습니다.('+ip+')')
405 res.redirect('/board/read/composer/'+idx_); 465 res.redirect('/board/read/composer/'+idx_);
406 }); 466 });
...@@ -440,7 +500,7 @@ router.get('/read/composer/:idx', function(req,res,next){ ...@@ -440,7 +500,7 @@ router.get('/read/composer/:idx', function(req,res,next){
440 var vidarr = [] 500 var vidarr = []
441 for(var i=0; i<picvideos.length; i++){ 501 for(var i=0; i<picvideos.length; i++){
442 var picadd = "../../../assets/img/" + picvideos[i].picname; 502 var picadd = "../../../assets/img/" + picvideos[i].picname;
443 - var vidadd = "../../../assets/video/" + picvideos[i].vidname; 503 + var vidadd = "../../../assets/img/" + picvideos[i].vidname;
444 if(picvideos[i].picname != null){ 504 if(picvideos[i].picname != null){
445 picarr.push(picadd) 505 picarr.push(picadd)
446 } 506 }
...@@ -647,7 +707,7 @@ router.get('/write/singer', function(req,res,next){ ...@@ -647,7 +707,7 @@ router.get('/write/singer', function(req,res,next){
647 } 707 }
648 }) 708 })
649 709
650 -router.post('/write/singer', function(req,res,next){ 710 +router.post('/write/singer', uploadpic.any(), function(req,res,next){
651 var ip = requestIp.getClientIp(req); 711 var ip = requestIp.getClientIp(req);
652 var nickname = req.user.nickname // var name = req.body.name 712 var nickname = req.user.nickname // var name = req.body.name
653 var title = req.body.title 713 var title = req.body.title
...@@ -669,6 +729,31 @@ router.post('/write/singer', function(req,res,next){ ...@@ -669,6 +729,31 @@ router.post('/write/singer', function(req,res,next){
669 if(!idx_) // 글이 없으면 NULL 729 if(!idx_) // 글이 없으면 NULL
670 idx_ = 1; 730 idx_ = 1;
671 731
732 + var piccount=0;
733 + var vidcount=0;
734 + for(var i=0; i<req.files.length;i++){
735 + if(req.files[i].mimetype.slice(0,5) == "image"){
736 + piccount += 1
737 + }
738 + else if(req.files[i].mimetype.slice(0,5) == "video"){
739 + vidcount += 1
740 + }
741 + }
742 + for(var i=0;i<piccount;i++){
743 + var sql_picupload = "insert into picvideo(picname, bulletin_id, boardtitle) values(?,?,'singer');"
744 + var picdata = [req.files.shift().filename, idx_]
745 + board.query(sql_picupload, picdata, function(err,rows) {
746 + if (err) console.error("err : " + err);
747 + })
748 + }
749 + for(var i=0;i<vidcount;i++){
750 + var sql_vidupload = "insert into picvideo(vidname, bulletin_id, boardtitle) values(?,?,'singer');"
751 + var viddata = [req.files.shift().filename, idx_]
752 + board.query(sql_vidupload, viddata, function(err,rows) {
753 + if (err) console.error("err : " + err);
754 + })
755 + }
756 +
672 console.log(logString+req.user.ID+'('+nickname+') 유저가 가수 구인 '+idx_+'번 게시글을 작성했습니다.('+ip+')') 757 console.log(logString+req.user.ID+'('+nickname+') 유저가 가수 구인 '+idx_+'번 게시글을 작성했습니다.('+ip+')')
673 res.redirect('/board/read/singer/'+idx_); 758 res.redirect('/board/read/singer/'+idx_);
674 }); 759 });
...@@ -708,7 +793,7 @@ router.get('/read/singer/:idx', function(req,res,next){ ...@@ -708,7 +793,7 @@ router.get('/read/singer/:idx', function(req,res,next){
708 var vidarr = [] 793 var vidarr = []
709 for(var i=0; i<picvideos.length; i++){ 794 for(var i=0; i<picvideos.length; i++){
710 var picadd = "../../../assets/img/" + picvideos[i].picname; 795 var picadd = "../../../assets/img/" + picvideos[i].picname;
711 - var vidadd = "../../../assets/video/" + picvideos[i].vidname; 796 + var vidadd = "../../../assets/img/" + picvideos[i].vidname;
712 if(picvideos[i].picname != null){ 797 if(picvideos[i].picname != null){
713 picarr.push(picadd) 798 picarr.push(picadd)
714 } 799 }
...@@ -915,7 +1000,7 @@ router.get('/write/free', function(req,res,next){ ...@@ -915,7 +1000,7 @@ router.get('/write/free', function(req,res,next){
915 } 1000 }
916 }) 1001 })
917 1002
918 -router.post('/write/free', function(req,res,next){ 1003 +router.post('/write/free', uploadpic.any(), function(req,res,next){
919 var ip = requestIp.getClientIp(req); 1004 var ip = requestIp.getClientIp(req);
920 var nickname = req.user.nickname // var name = req.body.name 1005 var nickname = req.user.nickname // var name = req.body.name
921 var title = req.body.title 1006 var title = req.body.title
...@@ -937,6 +1022,31 @@ router.post('/write/free', function(req,res,next){ ...@@ -937,6 +1022,31 @@ router.post('/write/free', function(req,res,next){
937 if(!idx_) // 글이 없으면 NULL 1022 if(!idx_) // 글이 없으면 NULL
938 idx_ = 1; 1023 idx_ = 1;
939 1024
1025 + var piccount=0;
1026 + var vidcount=0;
1027 + for(var i=0; i<req.files.length;i++){
1028 + if(req.files[i].mimetype.slice(0,5) == "image"){
1029 + piccount += 1
1030 + }
1031 + else if(req.files[i].mimetype.slice(0,5) == "video"){
1032 + vidcount += 1
1033 + }
1034 + }
1035 + for(var i=0;i<piccount;i++){
1036 + var sql_picupload = "insert into picvideo(picname, bulletin_id, boardtitle) values(?,?,'free');"
1037 + var picdata = [req.files.shift().filename, idx_]
1038 + board.query(sql_picupload, picdata, function(err,rows) {
1039 + if (err) console.error("err : " + err);
1040 + })
1041 + }
1042 + for(var i=0;i<vidcount;i++){
1043 + var sql_vidupload = "insert into picvideo(vidname, bulletin_id, boardtitle) values(?,?,'free');"
1044 + var viddata = [req.files.shift().filename, idx_]
1045 + board.query(sql_vidupload, viddata, function(err,rows) {
1046 + if (err) console.error("err : " + err);
1047 + })
1048 + }
1049 +
940 console.log(logString+req.user.ID+'('+nickname+') 유저가 자유게시판 '+idx_+'번 게시글을 작성했습니다.('+ip+')') 1050 console.log(logString+req.user.ID+'('+nickname+') 유저가 자유게시판 '+idx_+'번 게시글을 작성했습니다.('+ip+')')
941 res.redirect('/board/read/free/'+idx_); 1051 res.redirect('/board/read/free/'+idx_);
942 }); 1052 });
...@@ -976,7 +1086,7 @@ router.get('/read/free/:idx', function(req,res,next){ ...@@ -976,7 +1086,7 @@ router.get('/read/free/:idx', function(req,res,next){
976 var vidarr = [] 1086 var vidarr = []
977 for(var i=0; i<picvideos.length; i++){ 1087 for(var i=0; i<picvideos.length; i++){
978 var picadd = "../../../assets/img/" + picvideos[i].picname; 1088 var picadd = "../../../assets/img/" + picvideos[i].picname;
979 - var vidadd = "../../../assets/video/" + picvideos[i].vidname; 1089 + var vidadd = "../../../assets/img/" + picvideos[i].vidname;
980 if(picvideos[i].picname != null){ 1090 if(picvideos[i].picname != null){
981 picarr.push(picadd) 1091 picarr.push(picadd)
982 } 1092 }
...@@ -1183,7 +1293,7 @@ router.get('/write/suggestion', function(req,res,next){ ...@@ -1183,7 +1293,7 @@ router.get('/write/suggestion', function(req,res,next){
1183 } 1293 }
1184 }) 1294 })
1185 1295
1186 -router.post('/write/suggestion', function(req,res,next){ 1296 +router.post('/write/suggestion', uploadpic.any(), function(req,res,next){
1187 var ip = requestIp.getClientIp(req); 1297 var ip = requestIp.getClientIp(req);
1188 var nickname = req.user.nickname // var name = req.body.name 1298 var nickname = req.user.nickname // var name = req.body.name
1189 var title = req.body.title 1299 var title = req.body.title
...@@ -1205,6 +1315,31 @@ router.post('/write/suggestion', function(req,res,next){ ...@@ -1205,6 +1315,31 @@ router.post('/write/suggestion', function(req,res,next){
1205 if(!idx_) // 글이 없으면 NULL 1315 if(!idx_) // 글이 없으면 NULL
1206 idx_ = 1; 1316 idx_ = 1;
1207 1317
1318 + var piccount=0;
1319 + var vidcount=0;
1320 + for(var i=0; i<req.files.length;i++){
1321 + if(req.files[i].mimetype.slice(0,5) == "image"){
1322 + piccount += 1
1323 + }
1324 + else if(req.files[i].mimetype.slice(0,5) == "video"){
1325 + vidcount += 1
1326 + }
1327 + }
1328 + for(var i=0;i<piccount;i++){
1329 + var sql_picupload = "insert into picvideo(picname, bulletin_id, boardtitle) values(?,?,'suggestion');"
1330 + var picdata = [req.files.shift().filename, idx_]
1331 + board.query(sql_picupload, picdata, function(err,rows) {
1332 + if (err) console.error("err : " + err);
1333 + })
1334 + }
1335 + for(var i=0;i<vidcount;i++){
1336 + var sql_vidupload = "insert into picvideo(vidname, bulletin_id, boardtitle) values(?,?,'suggestion');"
1337 + var viddata = [req.files.shift().filename, idx_]
1338 + board.query(sql_vidupload, viddata, function(err,rows) {
1339 + if (err) console.error("err : " + err);
1340 + })
1341 + }
1342 +
1208 console.log(logString+req.user.ID+'('+nickname+') 유저가 건의사항 '+idx_+'번 게시글을 작성했습니다.('+ip+')') 1343 console.log(logString+req.user.ID+'('+nickname+') 유저가 건의사항 '+idx_+'번 게시글을 작성했습니다.('+ip+')')
1209 res.redirect('/board/read/suggestion/'+idx_); 1344 res.redirect('/board/read/suggestion/'+idx_);
1210 }); 1345 });
...@@ -1244,7 +1379,7 @@ router.get('/read/suggestion/:idx', function(req,res,next){ ...@@ -1244,7 +1379,7 @@ router.get('/read/suggestion/:idx', function(req,res,next){
1244 var vidarr = [] 1379 var vidarr = []
1245 for(var i=0; i<picvideos.length; i++){ 1380 for(var i=0; i<picvideos.length; i++){
1246 var picadd = "../../../assets/img/" + picvideos[i].picname; 1381 var picadd = "../../../assets/img/" + picvideos[i].picname;
1247 - var vidadd = "../../../assets/video/" + picvideos[i].vidname; 1382 + var vidadd = "../../../assets/img/" + picvideos[i].vidname;
1248 if(picvideos[i].picname != null){ 1383 if(picvideos[i].picname != null){
1249 picarr.push(picadd) 1384 picarr.push(picadd)
1250 } 1385 }
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
10 <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css" /> 10 <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700,300italic,400italic,700italic" rel="stylesheet" type="text/css" />
11 <!-- Core theme CSS (includes Bootstrap)--> 11 <!-- Core theme CSS (includes Bootstrap)-->
12 <link href="/css/styles.css?after" rel="stylesheet" /> 12 <link href="/css/styles.css?after" rel="stylesheet" />
13 +
14 + <meta charset="UTF-8">
15 + <meta name="viewport" content="width=device-width, initial-scale=1.0">
16 + <meta http-equiv="X-UA-Compatible" content="ie=edge">
13 </head> 17 </head>
14 <body> 18 <body>
15 <!-- Navigation--> 19 <!-- Navigation-->
...@@ -54,7 +58,7 @@ ...@@ -54,7 +58,7 @@
54 <% 58 <%
55 } 59 }
56 %> 60 %>
57 - <form action="/board/write/<%=addr%>" method="post"> 61 + <form action="/board/write/<%=addr%>" method="post" enctype="multipart/form-data">
58 62
59 <table border="1"> 63 <table border="1">
60 <tr> 64 <tr>
...@@ -70,10 +74,27 @@ ...@@ -70,10 +74,27 @@
70 <td><textarea name="content" id="content" cols="30" rows="10" required></textarea></td> 74 <td><textarea name="content" id="content" cols="30" rows="10" required></textarea></td>
71 </tr> 75 </tr>
72 <tr> 76 <tr>
77 + <td>
78 + 사진 업로드
79 + </td>
80 + <td>
81 + <input type='file' name='uploadpic' id='uploadpic' multiple='multiple' />
82 + </td>
83 + </tr>
84 + <tr>
85 + <td>
86 + 동영상 업로드
87 + </td>
88 + <td>
89 + <input type='file' name='uploadpic' id='uploadpic' multiple='multiple' />
90 + </td>
91 + </tr>
92 + <tr>
73 <td colspan="2"> 93 <td colspan="2">
74 <button type="submit">글쓰기</button> 94 <button type="submit">글쓰기</button>
75 </td> 95 </td>
76 </tr> 96 </tr>
97 +
77 </table> 98 </table>
78 </form> 99 </form>
79 </div> 100 </div>
......