htmldownloadhttpresponsecontent-disposition

How to use Content-disposition to force a file downloading?


I want to force the browser to download a pdf file.

I am using the following code :

<a href="../doc/quot.pdf" target=_blank>Click here to Download quotation</a>

It makes the browser open the pdf in a new window, but I want it to download to the hard drive when a user clicks it.

I found that Content-disposition is used for this, but how do I use it in my case?


Solution

  • On the HTTP Response where you are returning the PDF file, ensure the content disposition header looks like:

    Content-Disposition: attachment; filename=quot.pdf;
    

    See content-disposition on the wikipedia MIME page.