View pdf file in browser instead of downloading

自闭症网瘾萝莉.ら 提交于 2019-12-03 17:37:07

问题


header("Content-Length: " . filesize ('theme/assets/pdf/ci.pdf' ) ); 
header("Content-type: application/pdf"); 
header("Content-disposition: attachment;     
filename=".basename('theme/assets/pdf/ci.pdf'));
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
$filepath = readfile('theme/assets/pdf/ci.pdf');

Hi friends i've code of this type. my requirement is i've to display the loaded pdf(open the pdf in browser) in browser but where as now the pdf is downloaded to hard disk . instead I would like to view the file in browser .


回答1:


You need to change the Content-disposition to inline.

Change

header("Content-disposition: attachment;     
filename=".basename('theme/assets/pdf/ci.pdf'));

To:

header("Content-disposition: inline;     
filename=".basename('theme/assets/pdf/ci.pdf'));



回答2:


Downloading or Opening of a PDF file depends on setting in the browser.

Browser Setting to Open the PDF File instead of download:

Open PDFs in Chrome On your computer, open Chrome. At the top right, click More Settings. At the bottom, click Advanced. Under "Privacy and security," click Content settings. Near the bottom, click PDF documents. Turn off Download PDF files instead of automatically opening them in Chrome.

Setting in Mozilla Firefox

  1. Click on Extreme Right 3 lines.
  2. Click on Options
  3. In General Selection go to Applications
  4. Set for PDF File as "Preview in Firefox"


来源:https://stackoverflow.com/questions/34891513/view-pdf-file-in-browser-instead-of-downloading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!