Superlative Solutions' HelpDesk Language
 
Information
Article ID34
Created On12/15/2008
Modified12/15/2008
Force download of file
This article describes how to "force" a client browser to download a file rather than causing it to appear embedded in the browser. This is often desired when you want a user to have the opportunity to save or view a file, such as a PDF.

The example shown below is for a PDF, however, you could use a different MIME type for any other type of file:

<cfscript>
    phyFile = "d:\temp\sample.pdf";
</cfscript>

<!--- Set CFHEADER and CFCONTENT to force download --->
<!--- The "filename" in CFHEADER specifies the default name if save is choosen --->
<cfheader name="Content-Disposition" value="attachment; filename=sample.pdf">
<cfcontent type="application/pdf" file="#phyFile#">