问题
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