View pdf file in browser instead of downloading

user1894647 picture user1894647 · Jan 20, 2016 · Viewed 21.9k times · Source
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 .

Answer

Pupil picture Pupil · Jan 20, 2016

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'));