Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php symfony:setHttpHeader()不';不起作用,header()不起作用_Php_Symfony1_Apache2_Http Headers_Symfony 1.4 - Fatal编程技术网

Php symfony:setHttpHeader()不';不起作用,header()不起作用

Php symfony:setHttpHeader()不';不起作用,header()不起作用,php,symfony1,apache2,http-headers,symfony-1.4,Php,Symfony1,Apache2,Http Headers,Symfony 1.4,我在symfony中构建了一个简单的操作,它通过wkhtmltopdf生成一个PDF文件,并将其输出到浏览器 代码如下: $response = $this->getResponse(); $response->setContentType('application/pdf'); $response->setHttpHeader('Content-Disposition', "attachment; filename=filename.pdf"); $respo

我在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;
这在我的本地开发环境中运行良好-我的浏览器按预期获取标题,显示下载对话框

现在我更新了测试环境,用PHP5.3.5-0.dotdeb.0运行Apache2.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 bug,还是php或apache2配置问题?我不明白-/


提前谢谢

我唯一的区别是:

$response = $this->getContext()->getResponse();
$response->clearHttpHeaders();
你的问题是:

return sfView::NONE;
将此更改为:

return sfView::HEADERS_ONLY;
编辑由于额外评论而更新

由于您试图下载pdf,因此处理问题的方法不正确。不要使用
sendContent()
。请参见下文(这是我编写的一个生产站点中的一个片段,已证明可以在所有主要浏览器中使用):


我也有同样的问题。只需在文件名周围加上双引号(“)

$this->getResponse()->setHttpHeader('Content-Disposition', 'attachment; filename="'.$filename.'"');


@teonanacatl…选择一个帐户并使用它。目前您显然使用了两个不同的帐户。并且只使用HEADER_,而不使用HEADER_。如果不添加$this->getResponse()->sendHttpHeaders(),这对我是不起作用的;
$this->getResponse()->setHttpHeader('Content-Disposition', 'attachment; filename="'.$filename.'"');
header('Content-Disposition: attachment; filename="'.$filename.'"');