問題描述
我有一個問題,我該如何做這樣的事情:
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,我已經(jīng)嘗試過:
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 中的區(qū)別.
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');
根據(jù)瀏覽器的不同,您可能還必須設置 Content-Length
或將 Content-type
更改為一個的組合(多個標題)或多個 application/force-download
、application/octet-stream
和/或 application/download
.正如我在評論中所寫,有時緩存標頭可能會干擾您的下載.檢查以查看發(fā)送了哪些緩存頭.
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模板網(wǎng)!