-1

How can I download a PDF file and Redirect the another Route in Laravel 5.1.

For Download a File

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

Karthik mathesh
  • 203
  • 1
  • 4
  • 12

1 Answers1

0

That's how I have downloading a file in browser and it gets downloaded.

  $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;
       }
Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78