新手求教,表单提交rename文件报错!
发布于 9 年前 作者 lx1412 4954 次浏览 最后一次编辑是 8 年前 来自 问答
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";没用
3 回复

我记得跨盘符重命名不行?

@i5ting 谢谢,试一试

回到顶部