How do I force a file to download instead of displaying inline in IE, Firefox and other browsers?

You can force a file to download by using a combination of the <cfheader> and <cfcontent> tags. We'll use a jpg for this example. It will work for any file type however.

<cfheader name="content-disposition" value="attachment;filename=example.jpg">
<cfcontent type="image/jpeg" file="C:\files\example.jpg">

Note the use of filename in the <cfheader> tag. This allows you to give another name to the file being downloaded.

This question was written by Emmet McGovern
It was last updated on January 24, 2006.


Display and Layout


comments powered by Disqus