app.post('/upload’,function(req,res){
var form = new formidable.IncomingForm();
form.encoding = 'utf-8’;
form.uploadDir = __dirname + '/public/uploads/’;
form.keepExtensions = true;
form.maxFieldsSize = 210241024;
form.parse( req, function( err , fields , files ){
if(err){ //console.log(err);
res.redirect(‘admin/stageHome’); ///???
}
var filesName = req.files.fulAvatar.name, //
filesType = req.files.fulAvatar.type; if(filesName == “” ){ //
console.log(‘There is no file !’);
return;
}
if( !(!/.(gif|jpg|jpeg|bmp|png)$/.exec(filesName)) ){ // 检测文件格式是否为gif,jpg,jpeg,bmp,png
var suffixName = /\w{1,4}$/.exec(filesType)[0]; //获取后缀名
var avatarName = code.generateRandomCode(12) + code.gotTime() + ‘.’ + suffixName;
var newPath = form.uploadDir + avatarName;
var resPath = req.files.fulAvatar.path;
fs.renameSync(resPath, newPath); //重命名
}
else{
console.log(‘不支持的文件格式 !’);
return;
}
}
console.log(‘success!’);
});
res.render('stageHome’,{title:’’}); // 这一句 ???问题地方
});
"加问号问题地方"这一句加上去之后,图片就无法上传成功,
不加这一句网页一直处于响应状态或网页报错,但图片却仍可以成功上传
请高人指点如何解决!
先谢过了!!!
form.parse( req, function( err , fields , files ){
.........
........
if( !(!/.(gif|jpg|jpeg|bmp|png)$/.exec(filesName)) ){ // 检测文件格式是否为gif,jpg,jpeg,bmp,png
fs.renameSync(resPath, newPath); //重命名
res.render('stageHome’,{title:’’});
}
..........
});
callback