Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 Force Download a pdf File [closed]

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.

I Solved it- Answer is:

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.

like image 913
Ahmed Badawy Avatar asked Feb 11 '15 22:02

Ahmed Badawy


People also ask

How do I force a PDF file to download?

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.

How do I get pdfs out of storage in laravel?

$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"' ]);

How do I save a PDF in laravel as a URL?

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.


1 Answers

Remove the headers, they're not necessary. In L5, you can do

return response()->download($file, "Ahmed Badawy - CV.pdf");

Please read the docs.

like image 100
rdiz Avatar answered Oct 14 '22 01:10

rdiz