Zend Framework how to set headers(Zend Framework 如何设置标题)
问题描述
我有一个问题,我该如何做这样的事情:
I have a question, how can I do something like this:
header("Content-Disposition: inline; filename=result.pdf");
header("Content-type: application/x-pdf");
使用 Zend Framework,我已经尝试过:
With Zend Framework, I have tried:
$this->getResponse()
->setHeader('Content-Disposition:inline', ' filename=result.pdf')
->setHeader('Content-type', 'application/x-pdf');
但不能正常工作.
推荐答案
您设置响应标头的语句有点格式错误:
Your statement to set the response headers is slightly malformed:
$this->getResponse()
->setHeader('Content-Disposition', 'inline; filename=result.pdf')
->setHeader('Content-type', 'application/x-pdf');
以上应该可以工作 - 请注意 Content-Disposition
-header 中的区别.
The above should work - please note the difference in the Content-Disposition
-header.
顺便说一句...当您想强制下载框(而不是在浏览器中加载文档)时,您应该使用 Content-Disposition
attachment
.
By the way... When you want to force a download box (instead of loading the document in the browser) you should use the Content-Disposition
attachment
.
$this->getResponse()
->setHeader('Content-Disposition', 'attachment; filename=result.pdf')
->setHeader('Content-type', 'application/x-pdf');
根据浏览器的不同,您可能还必须设置 Content-Length
或将 Content-type
更改为一个的组合(多个标题)或多个 application/force-download
、application/octet-stream
和/或 application/download
.正如我在评论中所写,有时缓存标头可能会干扰您的下载.检查以查看发送了哪些缓存头.
Depending on the browser it may be possible that you also have to set the Content-Length
or change the Content-type
to a combination (multiple headers) of one or more of application/force-download
, application/octet-stream
and/or application/download
. And as I wrote in the comment sometimes caching headers may interfere with your download. Check to see which caching-headers are sent.
这篇关于Zend Framework 如何设置标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Zend Framework 如何设置标题


- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01