0

I am using Laravel 4.2 and want to make a download response using Response::download. So I used the following code:

$headers = array(
    'Content-Type: application/vnd.android.package-archive',
);
return Response::download(URL::to("assets/install.apk"), "tracking.apk", $headers);

But I got a FileNotFoundException exception. Then, I found this answer and changed my codes to:

$headers = array(
    'Content-Type: application/vnd.android.package-archive',
);
return Response::download(public_path() . "/assets/install.apk", "tracking.apk", $headers);

Now, it works. However, my question is what was wrong with URL::to?

Community
  • 1
  • 1

1 Answers1

2

Response::download expects a file system path such as /srv/http/some/file rather than an URL which would be http://hostname/some/file.

From the documentation :

Response::download($pathToFile);

You can also use optional parameters to set the name of the file that'll be saved on the client's side and an array additional headers like so :

Response::download($pathToFile, $name, $headers);