Zend Framework如何设置标题 [英] Zend Framework how to set headers

查看:77
本文介绍了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标头中的区别.

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-downloadapplication/octet-stream和/或<的一个或多个的组合(多个标题). c7>.正如我在评论中所写,有时缓存标头可能会干扰您的下载.检查发送哪些缓存头.

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如何设置标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆