3

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.

Ben
  • 261
  • 1
  • 2
  • 16

2 Answers2

11

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)

DPP
  • 12,146
  • 2
  • 46
  • 45
3

Assuming you have stored the file in the public folder under a folder called file and the file name is called download.pdf, (public/file/download.pdf);

public function downloadPdfFile()
{
     $filepath = public_path('file/download.pdf');
     return Response()->download($filepath);
}
Constantine
  • 656
  • 9
  • 14
Mundruku
  • 89
  • 1
  • 5