Forcing SaveAs using the HTTP header
In order to force the browser to show SaveAs dialog when clicking a hyperlink you have to include the following header in HTTP response of the file to be downloaded:
Content-Disposition: attachment; filename=
Where is the filename you want to appear in SaveAs dialog (like finances.xls or mortgage.pdf) – without symbols.
You have to keep the following in mind:
- The filename should be in US-ASCII charset.
- The filename should not have any directory path information specified.
- The filename should not be enclosed in double quotes even though most browsers will support it.
- Content-Type header should be before Content-Disposition.
- Content-Type header should refer to an unknown MIME type (at least until the older browsers go away).
before you use this header.