流式传输 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.
相关文章