Show PDF file in PHP

If you want to show your PDF file in PHP, you can put the code as follow :

———————

<?php

$pdf=’Showing.pdf’;
header(‘Content-type: application/pdf’);

header(‘Content-Disposition: attachment; filename=”‘.pdf.'”‘);

readfile($pdf);
?>

————————–

Note : The above code will open/ save PDF file as attachment. If you want to show the PDF file directly into same window, you can change the Content-disposition type into inline. So, the line

header(‘Content-Disposition: attachment; filename=”‘.pdf.'”‘);” should be change into :

header(‘Content-Disposition: inline; filename=”‘.pdf.'”‘);

——————————-

There is many option can be used for header field in PHP. For complete reference, you can follow this link : http://www.faqs.org/rfcs/rfc2183

Hope this article can be useful.


Advertisements