Tuesday, 6 September 2011

Forcing a download dialog in the browser

If we have a link in our website to the resource, that can be opened in the browser itself, by default the resource will be open in the browser . But what can we do to have a link that will activate download instead? To force the resource to be downloaded by default, in the http response we should add header
Content-Disposition: attachment;filename="our_file_name"

To read more about http headers look at: http://en.wikipedia.org/wiki/List_of_HTTP_header_fields

No comments: