3

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

我如何让 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>
4

1 回答 1

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

应该这样做

于 2012-05-31T01:25:49.717 回答