发送标题以下载PDF时,Safari附加.html

时间:2010-04-29 02:27:30

标签: php pdf http-headers kohana dompdf

以下是请求和响应标头

http://www.example.com/get/pdf

GET /~get/pdf HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://www.example.com
Cookie: etc 

HTTP/1.1 200 OK
Date: Thu, 29 Apr 2010 02:20:43 GMT
Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By: Me
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Cache-Control: private
Content-Disposition: attachment; filename="File #1.pdf"
Content-Length: 18776
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
----------------------------------------------------------

基本上,响应头是由DOMPDF的stream()方法发送的。

在Firefox中,文件提示为File #1.pdf。但是,在Safari中,文件保存为File #1.pdf.html

有谁知道为什么Safari会将html扩展名附加到文件名中?

我也在使用Kohana 3,通过控制器方法提供PDF。

4 个答案:

答案 0 :(得分:10)

从我看到的内容类型不正确,我相信如果这个问题得到解决,你的问题就会得到解决。

答案 1 :(得分:2)

因为你告诉它它是HTML。修复您的MIME类型。

Content-Type: text/html; charset=utf-8

答案 2 :(得分:2)

你可以改变Kohana 3发送标题的方式......

$this->request->headers['Content-Type'] = File::mime($file);

答案 3 :(得分:2)

我通过添加die()来修复它;流式传输之后

$dompdf = new DOMPDF();
$dompdf->set_paper("a4", "portrait"); 
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream($invoice.".pdf");
die();