View PDF file in browser instead of downloading

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, I have a code of this type. by my requirement I have to show the downloaded pdf (open pdf in the browser) in the browser, but where now the pdf is downloaded to the hard drive. instead, I would like to view the file in a browser.

+5
source share
2 answers

You need to change the Content-disposition to inline .

Edit

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

To:

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

You should know this:

 $pdf -> output ('your_file_pdf.pdf','I'); // which will helps to view the file 

and

 $pdf -> output ('your_file_pdf.pdf','D'); // which will helps to download the file. 

**so dont change** "You need to change the Content-disposition to inline as indicated in the answer above.

"

why, since the fpdf class file has a predefined switch statement for I and D, so there is no need to change the original function.

0
source

Source: https://habr.com/ru/post/1240978/


All Articles