Skip to content

Commit a85fda3

Browse files
committed
파일 삭제되게
1 parent d207484 commit a85fda3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

routes/admin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ router.post('/products/edit/:id', upload.single('thumbnail'), csrfProtection, fu
9494

9595
//그전에 지정되있는 파일명id을 받아온다.
9696
ProductsModel.findOne({ id: req.params.id }, function (err, product) {
97+
98+
if(req.file && product.thumbnail){//기존에 파일이 있었던 경우에만 파일 삭제 가능
99+
fs.unlinkSync(uploadDir+'/'+product.thumbnail);
100+
}
101+
97102
//넣을 변수 값을 셋팅한다
98103
var query = {
99104
name: req.body.name,

0 commit comments

Comments
 (0)