Content-Length usage.
Whenever I need for Coldfusion to force a file download I use code similar to this:
<cfset cFile = "somefile.txt">
<cfset cDirectory = "C:\">
<cfheader name="Content-Disposition" value="attachment;filename=""#cFile#""">
<cfcontent type="application/unknown" file="#cDirectory##cFile#">
The problem is that I can't see the total file size. The message varies by browser, but the situation is the same. The user can see that they have downloaded x of an unknown file size. That's not a show stopper, but it is annoying. I've been looking for a solution and finally stumbled onto the simple answer:
<cfset cFile = "somefile.txt">
<cfset cDirectory = "C:\">
<cfdirectory directory="#cDirectory#" action="LIST" name="qFile" filter="#cFile#">
<cfset nFilesize = qFile.Size>
<cfheader name="Content-Disposition" value="attachment;filename=""#cFile#""">
<cfheader name="Content-Length" value="#nFilesize#">
<cfcontent type="application/unknown" file="#cDirectory##cFile#">











There are no comments for this entry.
[Add Comment]