我有一个问题,我该如何做这样的事情:
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 如何设置标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
PHP、MySQL PDOException 的死锁异常代码?Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死锁异常代码?)
PHP PDO MySQL 可滚动游标不起作用PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滚动游标不起作用)
PHP PDO ODBC 连接PHP PDO ODBC connection(PHP PDO ODBC 连接)
使用 PDO::FETCH_CLASS 和魔术方法Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔术方法)
php pdo 只从 mysql 获取一个值;等于变量的值php pdo get only one value from mysql; value that equals to variable(php pdo 只从 mysql 获取一个值;等于变量的值)
MSSQL PDO 找不到驱动程序MSSQL PDO could not find driver(MSSQL PDO 找不到驱动程序)