相关疑难解决方法(0)

symfony:setHttpHeader()不起作用,header()没有

我在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;
Run Code Online (Sandbox Code Playgroud)

这在我的本地开发环境中工作正常 - 我的浏览器按预期获得标题,显示下载对话.

现在我更新了我的测试环境,用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
Run Code Online (Sandbox Code Playgroud)

如果我在动作中通过header()手动设置它们,Firebug会按预期显示标题.有人知道什么可能是错的吗?它是symfony bug,还是php或apache2配置问题?我不明白.: - /

提前致谢!

php symfony1 apache2 http-headers symfony-1.4

6
推荐指数
1
解决办法
1万
查看次数

从Symfony行动发送附件/下载文件

我正在尝试通过操作传递CSV文件.响应中的mime类型仍显示为text/html.有人可以帮忙吗?谢谢

        //$this->setLayout(false);
        //$this->getUser()->shutdown();
        //sfConfig::set('sf_web_debug', false);
        $response = $this->getContext()->getResponse();
        $response = $this->getResponse();
        $response->clearHttpHeaders();
        $response->setHttpheader('Pragma: public', true);
        $response->addCacheControlHttpHeader('Cache-Control', 'must-revalidate');
        $response->setContentType('application/octet-stream', true);
        $response->setHttpHeader('Content-Description', 'File Transfer');
        $response->setHttpHeader('Content-Transfer-Encoding', 'binary', true);
        $response->setHttpHeader('Content-Length', filesize($file_path));
        $response->setHttpHeader('Content-Disposition', 'attachment; filename="' . $file_name . '"');
        $this->getResponse()->sendHttpHeaders();
        //$response->setContent(file_get_contents($file_path));
        //readfile($file_path);
        $this->renderText(file_get_contents($file_path));
        //return sfView::NONE;

        return sfView::HEADER_ONLY;
Run Code Online (Sandbox Code Playgroud)

相信我,在到达这里之前,我的搜索结果都是紫色的.正如你可以看到上面的所有排列和组合,我仍然无法实现这一点!

php attachment download http-headers symfony-1.4

1
推荐指数
1
解决办法
7203
查看次数