Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel download pdf in public folder

Tags:

laravel

I have a a pdf in public/downloads. I want to just link to it and have it download or open in browser. I tried hitting http://localhost:8000/downloads/brochure.pdf in the browser but I just get a white screen with no errors. In Chrome DevTools > Network, it says the request was canceled. I'm inserting the URL via javascript so I can't use URL::to or link_to() like other answers on here have suggested.

Note: When I link to a css file in the same fashion as the brochure.pdf, the css appears in the browser.

like image 458
Ben Avatar asked Sep 14 '25 02:09

Ben


1 Answers

Path to file can be achieved like:

public function getDownload(){

        $file = public_path()."/downloads/info.pdf";
        $headers = array('Content-Type: application/pdf',);
        return Response::download($file, 'info.pdf',$headers);
    }

function will download file from : 'project/public/downloads' folder.

(don't forget to set-up routes and controller by yourself)

like image 181
DPP Avatar answered Sep 17 '25 07:09

DPP