提示错误:500 TypeError: Cannot read property ‘upload’ of undefined 应该是很白痴的问题…但是我发现不了…求各位大神救援!
app.get('/post', function(req, res){
res.render('post', {
title: '发表',
user: req.session.user,
success: req.flash('success').toString(),
error: req.flash('error').toString()
});
});
//post '/post'
app.post('/post', checkLogin);
app.post('/post', function(req, res){
var currentUser = req.session.user;
var tmp_path = req.files.upload.path;
console.log("temp_path->"+tmp_path);
var target_path = './public/images/' + req.files.upload.name;
fs.rename(tmp_path, target_path, function(err) {
if (err) throw err;
fs.unlink(tmp_path, function() {
if (err) throw err;
res.send('File uploaded to: ' + target_path + ' - ' + req.files.upload.size + ' bytes' + "target_path" + target_path);
});
});
post.save(function (err){
if (err){
req.flash('error', err);
return res.redirect('/');
}
req.flash('success', '发布成功!');
res.redirect('/');
});
})
1 回复