Laravel下载和重定向

时间:2016-05-27 12:36:30

标签: php laravel

如何在Laravel 5.1中下载PDF文件并重定向另一条路线。

下载文件

return response() - > download($ pathToFile);

1 个答案:

答案 0 :(得分:0)

我是如何在浏览器中下载文件并将其下载的。

  $fileName = "file.pdf";
       if (file_exists($fileName)) {
           header('Content-Description: File Transfer');
           header('Content-Type: application/octet-stream');
           header('Content-Disposition: attachment; filename="'.basename($fileName).'"');
           header('Expires: 0');
           header('Cache-Control: must-revalidate');
           header('Pragma: public');
           header('Content-Length: ' . filesize($fileName));
           readfile($fileName);
           //You can redirect to any route from here.
           exit;
       }