cfcontent force下载不向浏览器报告文件大小

时间:2012-05-31 00:17:05

标签: coldfusion download

我创建了一个允许客户下载文件的页面。麻烦的是,浏览器不知道文件有多大,也没有显示下载的进度......

如何让ColdFusion至少报告文件大小?而且,充其量,如何让浏览器下载栏检测文件大小和下载进度?

这是我的代码。

<cfparam name="delete_file" default="no">
<cfparam name="URL.d" default="n">
<cfparam name="content_type" default="image/jpeg">
<cfparam name="FileDownload" default="default.jpg">
<cfparam name="URL.file" default="default.jpg">
<cfparam name="folder" default="downloads">
<cfparam name="URL.folder" default="downloads">
<cfset folder = #URL.folder#>
<cfset FileDownload = #URL.file#>
<cfif URL.d IS "y">
    <cfset delete_file = "yes">
<cfelse>
    <cfset delete_file = "no">
</cfif>
<cfset exten = ListLast(FileDownload, ".")>

<cfswitch expression="#exten#">
<cfcase value="zip"><cfset content_type = "application/zip, application/x-zip, application/x-zip-compressed, application/octet-stream, application/x-compress, application/x-compressed, multipart/x-zip"></cfcase>
<cfcase value="ai"><cfset content_type = "application/illustrator"></cfcase>
<cfcase value="eps"><cfset content_type = "application/illustrator, application/octect-stream"></cfcase>
<cfcase value="pdf"><cfset content_type = "application/pdf, application/x-pdf, application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf"></cfcase>
<cfcase value="psd"><cfset content_type = "image/photoshop, image/x-photoshop, image/psd, application/photoshop"></cfcase>
<cfcase value="jpg"><cfset content_type = "image/jpeg"></cfcase>
<cfcase value="png"><cfset content_type = "image/png"></cfcase>
<cfcase value="tif"><cfset content_type = "image/tiff"></cfcase>
<cfdefaultcase><cfset content_type = "image/jpeg"></cfdefaultcase>
</cfswitch>

<cfoutput><cfheader name="content-disposition" value="attachment;filename=#FileDownload#">
<cfcontent type="#content_type#" file="#ExpandPath("./#folder#")#/#FileDownload#" deletefile="#delete_file#"></cfoutput>

1 个答案:

答案 0 :(得分:3)

<cfset fileToGetSizeOf = expandPath("./#folder#/#FileDownload#") />
<cfheader name="content-length" value="#getFileInfo(fileToGetSizeOf ).size#" />

应该这样做