如何从Edge或Chrome下载密码受保护的文件
从Edge或Chrome下载文件时,如何下载密码受保护的文件。当前,我有适用于不受密码保护的文件的代码。
以下是我正在使用的代码:
<cfif structKeyExists(URL, 'method') and URL.method eq 'download'>
<cfset file_name = URL.name />
<cfset path = URL.path />
<!--- The following if statements determine file type. --->
<cfif findNoCase('.doc', file_name) or findNoCase('.odt', file_name) or findNoCase('.rtf', file_name) >
<cfset file_type = 'application/msword' >
<cfelseif findNoCase('.pdf', file_name) >
<cfset file_type = 'application/pdf' >
<cfelseif findNoCase('.xls', file_name) or findNoCase('.xlt', file_name) or findNoCase('.csv', file_name)>
<cfset file_type = 'application/vnd.ms-excel' >
<cfelseif findNoCase('.tif', file_name) >
<cfset file_type = 'image' >
<cfelseif findNoCase('.jpg', file_name) >
<cfset file_type = 'image/jpeg' >
<cfelseif findNoCase('.url', file_name) or findNoCase('.lnk', file_name) >
<cfset file_type = 'text/uri-list' >
</cfif>
<!--- The following if checks which header to use --->
<cfif findNoCase('.msg', file_name) or findNoCase('.mdb', file_name) or findNoCase('.wmv', file_name) or findNoCase('.db', file_name)>
<!--- The following statements creates a downloadable link of the file. This is done by using cfheader and cfcontent --->
<cfheader name="Content-Disposition" value="attachment; filename=#file_name#">
<cfelse>
<!--- The following statements creates a downloadable link of the file. This is done by using cfheader and cfcontent --->
<cfheader name="Content-Disposition" value="inline; filename=#file_name#">
</cfif>
<!---Check if file type is available. If available, show type. --->
<cfif isDefined("file_type") >
<cfcontent type="#file_type#" file="#path#\#file_name#">
<!--- If file type is not found, display file anyways. --->
<cfelse>
<cfcontent file="#path#\#file_name#">
</cfif>
<cfabort>
</cfif>
How can I download password protected files when downloading the files from Edge or Chrome. Currently, I have code that works for files that are not password protected.
The following is the code I am using:
<cfif structKeyExists(URL, 'method') and URL.method eq 'download'>
<cfset file_name = URL.name />
<cfset path = URL.path />
<!--- The following if statements determine file type. --->
<cfif findNoCase('.doc', file_name) or findNoCase('.odt', file_name) or findNoCase('.rtf', file_name) >
<cfset file_type = 'application/msword' >
<cfelseif findNoCase('.pdf', file_name) >
<cfset file_type = 'application/pdf' >
<cfelseif findNoCase('.xls', file_name) or findNoCase('.xlt', file_name) or findNoCase('.csv', file_name)>
<cfset file_type = 'application/vnd.ms-excel' >
<cfelseif findNoCase('.tif', file_name) >
<cfset file_type = 'image' >
<cfelseif findNoCase('.jpg', file_name) >
<cfset file_type = 'image/jpeg' >
<cfelseif findNoCase('.url', file_name) or findNoCase('.lnk', file_name) >
<cfset file_type = 'text/uri-list' >
</cfif>
<!--- The following if checks which header to use --->
<cfif findNoCase('.msg', file_name) or findNoCase('.mdb', file_name) or findNoCase('.wmv', file_name) or findNoCase('.db', file_name)>
<!--- The following statements creates a downloadable link of the file. This is done by using cfheader and cfcontent --->
<cfheader name="Content-Disposition" value="attachment; filename=#file_name#">
<cfelse>
<!--- The following statements creates a downloadable link of the file. This is done by using cfheader and cfcontent --->
<cfheader name="Content-Disposition" value="inline; filename=#file_name#">
</cfif>
<!---Check if file type is available. If available, show type. --->
<cfif isDefined("file_type") >
<cfcontent type="#file_type#" file="#path#\#file_name#">
<!--- If file type is not found, display file anyways. --->
<cfelse>
<cfcontent file="#path#\#file_name#">
</cfif>
<cfabort>
</cfif>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论