简体   繁体   中英

How to download pdf file in laravel 5.6?

I have stored my pdf file in files folder inside public folder. Now, i have a "Download" button inside resources/views/admin/view_data.blade.php

How to download the pdf file when i click the download button??

Try this. When you click on the button call a route and a method then use this code. You can change directory path.

public function getDownload()
{
  //PDF file is stored under project/public/download/info.pdf
  $file= public_path(). "/download/info.pdf";

  $headers = array(
          'Content-Type: application/pdf',
        );

    return Response::download($file, 'filename.pdf', $headers);
}

只是一个小小的补充,如果您使用的是 IDE,以下内容将防止任何夸克return response()->download($file, 'filename.pdf' ,$headers);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM