【发布时间】:2011-03-07 10:43:09
【问题描述】:
我在 symfony 中构建了一个简单的操作,它通过 wkhtmltopdf 生成 PDF 文件并将其输出到浏览器。
代码如下:
$response = $this->getResponse();
$response->setContentType('application/pdf');
$response->setHttpHeader('Content-Disposition', "attachment; filename=filename.pdf");
$response->setHttpHeader('Content-Length', filesize($file));
$response->sendHttpHeaders();
$response->setContent(file_get_contents($file));
return sfView::NONE;
这在我的本地开发环境中运行良好 - 我的浏览器按预期获取标题,显示下载对话框。
现在我更新了我的测试环境,使用 PHP 5.3.5-0.dotdeb.0 运行 Apache 2.2.9-10+lenny9。 如果我现在为测试环境调用该 URL,我的浏览器不会获得任何自定义设置的标头:
Date Mon, 07 Mar 2011 10:34:37 GMT
Server Apache
Keep-Alive timeout=15, max=100
Connection Keep-Alive
Transfer-Encoding chunked
如果我在操作中通过 header() 手动设置它们,Firebug 会按预期显示标题。 有谁知道可能出了什么问题?是 symfony 错误,还是 php 或 apache2 配置问题?我不明白。 :-/
提前致谢!
【问题讨论】:
-
@teonanacatl... 选择您的一个帐户并使用它。目前,您显然正在使用两个不同的帐户。 stackoverflow.com/users/647993/teonanacatl 和 stackoverflow.com/users/480353/teonanacatl
标签: php symfony1 apache2 http-headers symfony-1.4