I want a php page to ‘display’ a pdf. Here is the code:
<?php
header("Content-type: application/pdf");
readfile('Reportage - Berlin.pdf'); //tried echo(readfile(...)) as well
?>
Not very complicated I think, but somehow firefox cant detect that this is a pdf. This works in Safari but in firefox, i get a prompt to download the file, so i get like a pdftest.php file. I know im getting my file because if I rename the extension to pdf, i can open it.
This seems too simple! am i missing something?
If you want it to open in the browser using Adobe Reader then that can also depend on the browser setting. The reason why it’s saying the filename is pdftest.php is because you’re not telling the browser what the filename is.
If you want to force the browser to download it, add this:
header('Content-Disposition: attachment; filename="downloaded.pdf"');