Reputation: 4232
laravel and nginx downloading files,I try it like this:
TestController.php
,passing variables to view:
public function test()
{
$filepath = '2017/demo.zip';
$filename = 'demo.zip';
return view('download', compact('filepath','filename'));
}
download.blade.php
,receiving the variables:
<?php
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename= {{$filename}}");
header('X-Accel-Redirect: /down/'. {{$filepath}} );
exit;
?>
Questions:
1、Is the content of download.blade.php
right? Or this file is not necessary?
2、If download.blade.php
is necessary,but the variables in {{ }}
can not be parsed, how to write it?
Upvotes: 0
Views: 452
Reputation: 896
there is no need to render view. you can use laravel response helper:
return response()->download(public_path('path_to_directory/demo.zip'));
Upvotes: 1