gpt4 book ai didi

coldfusion - cfcontent 强制下载不向浏览器报告文件大小

转载 作者:行者123 更新时间:2023-12-03 23:53:06 25 4
gpt4 key购买 nike

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

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

最佳答案

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

应该做

关于coldfusion - cfcontent 强制下载不向浏览器报告文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10825959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com