BlueDragon Blog
Here you'll find tips and information about making the most of BlueDragon, which offers several compelling implementation alternatives for your CFML applications. This blog was created originally by Charlie Arehart, who was New Atlanta CTO from 2003-2006.,He has since moved on to become an independent consultant but continues to answer comments raised in existing blog entries. BlueDragon continues, and you should look to the newer BlueDragon blog, from New Atlanta president, Vince Bonfanti, for more updated information.

Solving a challenge with CFHEADER specifying a file with spaces in its name

posted Friday, 2 December 2005

A reader on a mailing list raised a challenge where he found CFHEADER failing when the filename being specified for a Content-Disposition header had a space in it. When I helped him toward the solution, he thought the solution worth blogging. He had had trouble finding any solution.

He was using the following in conjunction with cfcontent:

<cfheader name="Content-Disposition" value="attachment; filename=#strFilename#">

The problem arose when they tried to specify a file with a space in the name (for example, "report for joe.xls"). It would truncate the filename when downloaded with Firefox. IE will download the file as "report for joe.xls", but Firefox will download the file as "report". 

He was at a loss and asked on the list, and I proposed that perhaps the value of the filename needed to be surrounded with quotes (single quotes since the VALUE attribute itself used double quotes). He reported back that this was close, but didn't work. For some reason, he instead had to change the VALUE attribute to use single quotes and the Filename within it to use double quotes, so the solution was:

<cfheader name="Content-Disposition" value='attachment; filename="#strFilename#"'>

He reported additionally that  he "made this change and tested it in IE6 and Firefox. It works for saving the file AND opening the file directly from the browser prompt. Tried with Word, PDF, txt, gif, and XLS files, all without trouble." He was reporting the concern with CFMX but I imagine it would also have been an issue on BlueDragon (it's not about the CFHEADER tag but rather the value being indicated to be sent in the HEADER itself).

Glad to help anyway.




1. Cliff Pearson left...
Monday, 13 March 2006 8:06 pm

Just a quick note to say thank you - I've been pulling my hair out over this problem (not that I can spare much! B->).

All the best

</cliff>


2. Charlie Arehart left...
Tuesday, 14 March 2006 12:00 pm

From one to another (follicly challenged), I hear you, and very glad to have been able to help (in more ways than the one!).


3. Carrie left...
Tuesday, 31 July 2007 3:38 pm

muchas gracias amigo!


4. Pam Wedel left...
Friday, 28 December 2007 1:00 pm

When I use this: <cfheader name="Content-Disposition" value='attachment; filename="#strFilename#.xls"'> it doesn't prompt to OPEN the file, only to SAVE or CANCEL the file. How can I get it to do all three? Thanks...


5. CA left...
Sunday, 30 December 2007 3:42 pm

Pam, I would expect that to be entirely controlled by the browser. You can find discussions to that effect in an experts-exchange discussion related to this. Go to the very bottom of the page at http://www.experts-exchange.c om/Software/Server_Software/Web_Servers/ColdFusion/Q_21822081.html

Sorry I can't be of more help.


6. Gary left...
Tuesday, 2 December 2008 6:53 pm

Just what I was looking for, worked a treat - thanks for posting. (And for once, I didn't have to spend an hour on google trying to find the answer!)