在流式传输PDF附件时如何强制“另存为"对话框 [英] How to force a Save As dialog when streaming a PDF attachment

查看:102
本文介绍了在流式传输PDF附件时如何强制“另存为"对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码将pdf流式传输到浏览器:

I am using the following code to stream a pdf to the browser:

header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Pragma: public");
header("Content-type:application/pdf");
header("Content-Disposition:attachment;filename=file.pdf");
echo $pdf;

工作正常,除了(无论如何在Chrome中)它只是保存文件"file.pdf"-它不会提示另存为"对话框,因此我可以重命名该文件(如果选择的话).

Works fine, except (in Chrome anyhow) it just saves the file "file.pdf" - it does not prompt a Save As dialog so I can rename the file, if I choose.

我怀疑这可能是与浏览器有关的事情之一,但是在传输要下载的pdf时是否可以用php标头强制使用另存为"对话框?

I suspect this may be one of those browser-dependent things, but is it possible to force a Save As dialog with the php headers when streaming a pdf for download?

(预先)感谢您的帮助

推荐答案

他们很可能具有在未选中(高级设置)的情况下要求在下载之前保存每个文件的位置.如果是这种情况,您将无能为力,因为这是他们的偏爱.

They most likely have Ask where to save each file before downloading unchecked (Advanced Settings). If this is the case, there's nothing you can do as this is their preference.

这篇关于在流式传输PDF附件时如何强制“另存为"对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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