How to force a Save As dialog when streaming a PDF attachment

亡梦爱人 提交于 2019-12-19 04:58:08

问题


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;

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.

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?

Thanks (in advance) for your help


回答1:


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.




回答2:


That behavior is controlled by the browser settings, so I don't think theres a way to force the "Save as" dialog to be opened.

You could try not specifying a name for the file, but I do think that it will just inherit the scripts name instead.




回答3:


You could try:

Content-Type = application/download


来源:https://stackoverflow.com/questions/9474553/how-to-force-a-save-as-dialog-when-streaming-a-pdf-attachment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!