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.
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->).
From one to another (follicly challenged), I hear you, and very glad to
have been able to help (in more ways than the one!).
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...
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
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!)