Sending http post request to php with many data using angular

108 views Asked by At

I would like to send filenames and filepath to php server using angular. My code looks like:

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

In $scope.files are stored the names of my files e.g

file1.txt,

file2.txt,

file3.txt

and I would like to send another parameter ($scope.source) where is stored filepath on server e.g

files/textfiles/.

1

There are 1 answers

0
Debasish Mohapatra On BEST ANSWER

See if this works,

$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;
  });