新手求教,表单提交rename文件报错!
var express = require('express');
var Photo = require('../modals/Photo');
var path = require('path');
var fs = require('fs');
var join = path.join;
var router = express.Router();
var multipart = require('connect-multiparty');
var formidable = require('formidable');
var multipartMiddleware = multipart();
router.get('/p', function (req, res, next) {
res.render('photos', {
title: 'photos',
});
});
router.get('/', function (req, res,next) {
res.render('photos/upload', {
title: 'upload-photo'
});
});
router.post('/', multipartMiddleware, function (req, res, next) {
var form = new formidable.IncomingForm();
form.uploadDir = "./public";
//console.log(path.normalize('../'));
var img = req.files.photo;
var name = req.body.name;
console.log(name);
var p= path.resolve('../photo/photos/'+img.name);
fs.rename(img.path, p, function (err) {
if (err) return next(err);
Photo.Setphoto(name, p);
console.log(path);
});
});
module.exports = router;
\n```
上传文件后报
Error: EXDEV: cross-device link not permitted, rename 'C:\Users\ADMINI~1\AppData\Local\Temp\c_3UyuFUPvyLtHv4JiATjsTw.css' -> 'K:\Node\express\photo\photos\1.css'
at Error (native)
有好心人解答一下吗
按网上的解决办法加了
form.uploadDir = "./public";没用