使用 angular 向 php 发送包含大量数据的 http post 请求

Sending http post request to php with many data using angular

我想使用 angular 将文件名和文件路径发送到 php 服务器。 我的代码如下所示:

    $http({
        method: 'POST',
        url: 'sample.php',
        data: "files=" + $scope.files,
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    }).success(function(data) {
        $scope.data = data;
      });
  };

$scope.files 中存储了我的文件的名称,例如

file1.txt,

file2.txt,

file3.txt

我想发送另一个参数 ($scope.source) 服务器上存储文件路径的位置,例如

files/textfiles/.

看看这是否有效,

$http({
    method: 'POST',
    url: 'sample.php',
    data: { 
             "files": $scope.files,
             "source": 'files/textfiles/'
          },
    transformRequest: function (obj) {
                          var str = [];
                          for (var p in obj)
                              str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                              return str.join("&");
                     },
    headers: {'Content-Type': 'application/x-www-form-urlencoded'}
    }).success(function(data) {
    $scope.data = data;
  });