Using php’s ability to call upon the browser to display a given PDF it doesn’t work on my web host. But it works on my local xamp server with apache.
PHP:
$title = $_GET['title'];
$loc = $_GET['loc'];
header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=".$title);
@readfile($loc);
Expected Output: Supposed to be the PDF document being rendered like it does on my local web server.
Actual but unwanted output:
%PDF-1.6 %���� 1638 0 obj <> endobj xref 1638 44 0000000016 00000 n …
Can be seen here:
http://neilau.me/view.php?title=business-studies-hsc-notes-2006.pdf&loc=pdf/criteria/business-studies/2006/business-studies-hsc-notes-2006.pdf
Is this fixed through changing something on my cpanel? As my code isn’t faulty… It works on my local web server.
2
Answers
Use this code
You need to make sure you are not sending any text before writing headers.
Example of what not to do:
Example of how to fix that:
In addition your script is very insecure. Here’s what you should do, your entire PHP script should be:
If you want to show things like a page title or a frame around it, you should use an iframe in another “wrapper” page: