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

发布于 2024-08-30 07:39:46 字数 1325 浏览 9 评论 0原文

这是请求和响应标头

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。

Here is the request and response headers

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
----------------------------------------------------------

Basically, the response headers are sent by DOMPDF's stream() method.

In Firefox, the file is prompted as File #1.pdf. However, in Safari, the file is saved as File #1.pdf.html.

Does anyone know why Safari is appending the html extension to the filename?

I'm also using Kohana 3, serving the PDF from a controller method.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

鲸落 2024-09-06 07:39:46

据我所知,内容类型不正确,我相信如果解决了这个问题,您的问题就会得到解决。

From what i see the content type is incorrect, i believe if that is fixed, your problem will be solved.

蓝天 2024-09-06 07:39:46

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

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

I've fixed it by adding die(); after streaming it

$dompdf = new DOMPDF();
$dompdf->set_paper("a4", "portrait"); 
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream($invoice.".pdf");
die();
原野 2024-09-06 07:39:46

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

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

Because you're telling it that it's HTML. Fix your MIME type.

Content-Type: text/html; charset=utf-8
偏闹i 2024-09-06 07:39:46

您可以更改 Kohana 3 发送标头的方式,如下所示...

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

You can change how Kohana 3 sends headers like so...

$this->request->headers['Content-Type'] = File::mime($file);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文