Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 将php文件上载端点转换为node.js/express_Angularjs_Node.js_Express - Fatal编程技术网

Angularjs 将php文件上载端点转换为node.js/express

Angularjs 将php文件上载端点转换为node.js/express,angularjs,node.js,express,Angularjs,Node.js,Express,抱歉,我以前没有在node.js中使用文件上载 目前,我使用angular服务,该服务使用FormData,并向php提交$http post请求,然后在那里通过move\u uploaded\u file()上传,工作正常 js代码 myApp.service('fileUpload', ['$http', function ($http) { this.uploadFileToUrl = function(file, uploadUrl){ var fd = new

抱歉,我以前没有在node.js中使用文件上载

目前,我使用angular服务,该服务使用
FormData
,并向php提交$http post请求,然后在那里通过
move\u uploaded\u file()
上传,工作正常

js代码

myApp.service('fileUpload', ['$http', function ($http) {
    this.uploadFileToUrl = function(file, uploadUrl){
        var fd = new FormData();
        fd.append('file', file);
        $http.post(uploadUrl, fd, {
            transformRequest: angular.identity,
            headers: {'Content-Type': undefined}
        })
        .success(function(){
        })
        .error(function(){
        });
    }
}]);

myApp.controller('myCtrl', ['$scope', 'fileUpload', function($scope, fileUpload){

    $scope.uploadFile = function(){
        var file = $scope.myFile;
        console.log('file is ' + JSON.stringify(file));
        var uploadUrl = "upload.php";
        fileUpload.uploadFileToUrl(file, uploadUrl);
    };

}]);
html


可能是@jakerella的副本,该解决方案不起作用
<input type="file" file-model="myFile"/>
<button ng-click="uploadFile()">upload me</button>
routes.post("/upload",function(req,res,next){
 console.log(req.Files); 
 console.log(req.body); 

  });