1

I have a standard angular code, that is triggered when button is clicked:

$scope.downloadAll = function () {   
  $http.get("download.php?id=" + $scope.id).success(function (data) {
    }).error(function () {
        $scope.status = "Error: can not download table data from server.";
    }); 
 }

but my php script returns a zip archive and its contents thus ends up in javascript variable, data. I would like to modify the behaviour so that the zip archive is offered by browser to store on local disk. How I would achieve that, keeping the angular button handler?

onkami
  • 8,791
  • 17
  • 90
  • 176

1 Answers1

0

In your angular controller, inject $window and use it like this:

$scope.downloadAll = function () {
  $window.location.href = "/download.php?id=" + $scope.id;
}

On the server, make sure that your zip file is served with the appropriate http headers to prompt a file download (content-disposition, mime type, ...).

marapet
  • 54,856
  • 12
  • 170
  • 184