主要原因page is changing into gray colors
是浏览器无法正确检测内容类型。
试试这个:
header("Content-type: $mimetype");
header('Content-Disposition: inline; filename="'.$question.'"'); // Filename should be there, not the content
代替 :
header('Content-type: $mimetype');
header('Content-Disposition: inline; filename="$question"');
您的引号似乎无效,因此未正确指定内容类型。
编辑
为了清楚起见,我们假设这$question
是二进制 PDF 内容。
这就是您的代码应该是什么:
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename=anything.pdf');
header('Content-Transfer-Encoding: binary');
echo $question;
错误解释
让我们讨论您的原始代码和您的错误。
$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";
再编辑一次
我有另一个查询...我想将文件名更改为 $year.pdf ..$ year 可能具有 2007 之类的值..我该怎么做???
试试这个 :
$year = '2013'; // Assign value
header('Content-Disposition: inline; filename='.$year.'.pdf');
代替:
header('Content-Disposition: inline; filename=anything.pdf');