user1922137
user1922137

Reputation:

Laravel Response::download throws a FileNotFoundException exception when using URL::to

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?

Upvotes: 0

Views: 1079

Answers (1)

user2629998
user2629998

Reputation:

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

Upvotes: 2

Related Questions