The main reason page is changing into gray colors is because the browser cannot correctly determine the type of content.
Try the following:
header("Content-type: $mimetype"); header('Content-Disposition: inline; filename="'.$question.'"');
Instead:
header('Content-type: $mimetype'); header('Content-Disposition: inline; filename="$question"');
It seems that you have invalid quotes, so the content type is not specified correctly.
EDIT
To clear, let's say $question is binary PDF content.
Here is what your code should look like:
header('Content-type: application/pdf'); header('Content-Disposition: inline; filename=anything.pdf'); header('Content-Transfer-Encoding: binary'); echo $question;
ERRORS DEVELOPING
Discuss the source code and your mistakes.
$mimetype = 'application/pdf'; $disposition = 'attachment'; // First error: you have single quotes here. So output is 'Content-type: $mimetype' instead of the 'Content-type: application/pdf' header('Content-type: $mimetype'); // Second error. Quotes again. Additionally, $question is CONTENT of your PDF, why is it here? header('Content-Disposition: inline; filename="$question"'); header('Content-Transfer-Encoding: binary'); // Also bad: strlen() for binary content? What for? header('Content-length: ' . strlen($question)); header('Accept-Ranges: bytes'); echo "$question";
ONE MORE EDITING
I have another request ... I want to change the file name to $ year.pdf .. $ year can have values ββlike 2007 .. how can I do this?
Try the following:
$year = '2013'; // Assign value header('Content-Disposition: inline; filename='.$year.'.pdf');
Instead:
header('Content-Disposition: inline; filename=anything.pdf');
source share