如何从Edge或Chrome下载密码受保护的文件

发布于 2025-02-11 18:41:39 字数 2236 浏览 1 评论 0原文

从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文