node+layui实现图片上传预览和删除功能




	
	
    
    
    


	
预览图:

node代码:

用的是express+multer模块

var storage = multer.diskStorage({
  	destination: function (req, file, cb) {
	    cb(null, './public/upload')
  	},
  	filename: function (req, file, cb) {
	  	var str = file.originalname.split('.');
	    cb(null, Date.now()+'.'+str[1]);
  	}
})
var upload = multer({ storage: storage });
app.post("/uploadImgs",upload.array("file",20),function(req,res,next){
	
	var arr = [];
	for(var i in req.files){
		
		arr.push(req.files[i].path);
	}
	res.json({
		code:200,
		data:arr
	})
})


你可能感兴趣的:(Node.js,JavaScript武器库,Node.js开发指南)