1

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 Answer 1

1

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;
  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.