【发布时间】:2014-02-24 14:15:50
【问题描述】:
我的服务器上有一个 PHP 脚本,用于创建和下载 PDF 文件。我已经在我的 Ubuntu 桌面计算机上通过 Chromium 客户端对其进行了测试,它可以正常下载并打开。
当我从 windows 7 和 windows 8 chrome 浏览器尝试时,文件下载但系统无法打开文件。错误读取,
“它要么不是受支持的类型,要么已损坏......”。
这里是提示下载的PHP代码:
<?php
...
ob_start();
include 'show_report.php';
$content = ob_get_clean();
$tmpfname = tempnam("/var/www/phpAJAX/Reports/", "pdf_");
$handle = fopen($tmpfname, "w");
fwrite($handle, $content);
fclose($handle);
shell_exec('mv '.$tmpfname.' '.$tmpfname.'.html');
$output = shell_exec('wkhtmltopdf --page-size Letter '.$tmpfname.'.html '.$tmpfname.'.pdf');
//echo $content;
header("Content-disposition: attachment; filename=".$_GET['report_name'].".pdf");
header("Content-type: application/pdf");
readfile($tmpfname.'.pdf');
?>
只是想知道是否有人能明白为什么会发生这种情况。
谢谢!
【问题讨论】:
-
我发现 Chrome 在标题方面非常非常敏感...我让它以纯文本形式转储 HTML 页面,因为我使用的是
Content-type而不是 @987654323 @ ...所以我首先尝试将Content-disposition更改为Content-Disposition和Content-type更改为Content-Type... 可能无济于事,但不会受到伤害。 -
感谢您的提示。那似乎没有解决它。很奇怪,我使用 sftp 将 PDF 文件下载到我的 windows 框并打开正常,但是在上面的脚本中使用 PHP 下载时显示错误...
标签: php windows pdf ubuntu download