Edited
i want to Force Download a pdf File in laravel 5.
in laravel 4 i used the following code:
$file= public_path(). "/site-docs/cv.pdf";
$headers = array(
'Content-Type: application/pdf',
'Content-Disposition:attachment; filename="cv.pdf"',
'Content-Transfer-Encoding:binary',
'Content-Length:'.filesize($file),
);
return \Response::download($file,"Ahmed Badawy - CV.pdf", $headers);
but in laravel 5 that doesn't work.it comes out with this error:
Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)
also i tried this:
return response()->download($file);
same error apeared... what can i do to force a download in laravel 5.
it was a server thing. thanks any way. you just enable this extension: php_fileinfo.dll in the php.ini file. then restart the server.
On your computers desktop, right click on the item. Choose the 'Send to' option and then choose 'Compressed (zip) folder'. This will place your download in a zip folder. When attaching your downloadable item, choose the one that has been placed in the zip folder.
$file = Storage::get('app/folder-name/example. pdf'); *or* $file = File::get('storage_path('app/folder-name/example. pdf'); return response()->file($file, [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'inline; filename="a. pdf"' ]);
Get the file contents to your local server and save it as pdf via Storage facade. Return the download in the response and delete once downloaded. That's about it.
Remove the headers, they're not necessary. In L5, you can do
return response()->download($file, "Ahmed Badawy - CV.pdf");
Please read the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With