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

查看:40
本文介绍了流式传输 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天全站免登陆