【发布时间】:2016-03-25 20:13:17
【问题描述】:
我想在网页中嵌入 PDF 文件。我需要动态生成 PDF,以便我可以先对用户进行身份验证,所以我在 Apache 上使用 XSendFile。当我访问浏览器并立即提供 PDF 文件供下载时,我拥有的 PHP 文件运行良好。这是我正在使用的代码(http://www.brighterlamp.com/2010/10/send-files-faster-better-with-php-mod_xsendfile/ 提供)
// Get a list of loaded Apache modules
$modules = apache_get_modules();
if (in_array('mod_xsendfile', $modules)) {
// Use XSendFile if possible
header ('X-Sendfile: ' . $pathToFile);
header ('Content-Type: ' . $documentMIME);
header ('Content-Disposition: attachment; filename="' . $actualFilename . '"');
exit;
} else {
// Otherwise, use the traditional PHP way..
header ('Content-Type: ' . $documentMIME);
header ('Content-Disposition: attachment; filename="' . $actualFilename . '"');
@ob_end_clean();
@ob_end_flush();
readfile($pathToFile);
exit;
}
到目前为止一切顺利。现在我想使用对象标签将此 PDF 嵌入网页中,例如:
<object data="dynamicpdf.php" type="application/pdf">
<p>PDF embed failed</a></p>
</object>
但这失败了。如果我将数据属性切换为静态 PDF 文件,那么它工作正常。
有什么想法吗?
【问题讨论】:
标签: php html x-sendfile