There has been quite a lot of discussion about how to make file download work properly
in various browsers.
Thomas Chiverton came up with a work-around for MSIE 5.x Win bugs that wouldn't
pick up the correct file name. Others had fixes for other browsers.
Thomas' solution used a popup window to trick MSIE. In his words it was "horrible".
Here's my contribution that builds on the work of Thomas and others.
I took the popup window approach a step further and substituted an invisible frame for
the popup window... less distraction for the user.
There are 3 programs:
DownloadSetup.cfm..... Sets Up the Invisible and Visible Frames
DownloadRequest.cfm... Initiates the Download request
DownloadFile.cfm...... Does the Download
I have tested this on IE 5.5 Win, NN 4.76 Mac, IE 5.0 Mac.
I need to reinstall IE 4.0 Win and NN 4.x Win to test there!
If anyone can verify that it works (or fails) on other versons/platforms, please
notify me... it will be greatly appreciated, as I need a solution for as many browsers
as possible.
TIA
Dick
Here's the code:
<!--- ------------------------------------------------------------ --->
<!--- DownLoadSetup.cfm --->
<!--- ------------------------------------------------------------ --->
<cfsetting EnableCFOutputOnly="Yes">
<cfparam name="ShowInvisible" default="">
<cfset FrameSize = "0">
<cfset Scrolling = "NO">
<cfif URL.ShowInvisible EQ "Yes">
<cfset FrameSize = 100>
<cfset Scrolling = "YES">
</cfif>
<cfoutput>
<html>
<head>
<title>File Download</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<frameset rows="#FrameSize#,*" cols="*" border="0" framespacing="0" frameborder="no">
<frame name="Invisible" src="Invisible.html" scrolling="#Scrolling#">
<frame name="Visible" src="DownLoadRequest.cfm" scrolling="auto">
</frameset>
<noframes>
<body bgcolor="FFFFFF" text="000000">
</body>
</noframes>
</html>
</cfoutput>
<cfsetting EnableCFOutputOnly="No">
<!--- ------------------------------------------------------------ --->
<!--- DownLoadRequest.cfm --->
<!--- ------------------------------------------------------------ --->
<cfsetting EnableCFOutputOnly="yes">
<cfset FileName = "SomeFileName">
<cfoutput>
<!--- dummy filename in URL needed for IE bug --->
<form method="post" target="Invisible"
action="DownLoadFile.cfm/#FileName#/">
<input type="Submit" name="DownloadNow" value="Download Now">
</form>
<!--- dummy filename in URL needed for IE bug --->
<a href="Javascript:void(0)"
onclick="parent.Invisible.location='DownLoadFile.cfm/#FileName#/';">
Download now</a>
</cfoutput>
<cfsetting EnableCFOutputOnly="no">
<!--- ------------------------------------------------------------ --->
<!--- DownLoadFile.cfm --->
<!--- ------------------------------------------------------------ --->
<cfsetting EnableCFOutputOnly="yes">
<cfset FilePath = "D:\SomeFilePath\">
<cfset FileName = "SomeFileName">
<cfset FileType = "SomeMimeType">
<cfset BadType = "-#FileType#-"> <!--- Make an Invalid Mime Type --->
<cfif ReFind("MSIE",cgi.HTTP_USER_AGENT)>
<cfheader name="Content-type" value="#BadType#">
<cfheader name="Content-Disposition" value="attachment; filename=#FileName#">
<cfcontent type="#BadType#" file="#FilePath##FileName#">
<cfelse>
<cfheader name="Content-type" value="#FileType#">
<cfheader name="Content-Disposition" value="attachment; filename=#FileName#">
<cfcontent type="#FileType#" file="#FilePath##FileName#">
</cfif>
<cfsetting EnableCFOutputOnly="no">
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists