How to force a Save As dialog when streaming a PDF attachment(流式传输 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 附件时如何强制使用另存为对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:流式传输 PDF 附件时如何强制使用另存为对话框
基础教程推荐
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
