Asp classic ASP经典下载文件脚本

Asp classic ASP经典下载文件脚本,asp-classic,vbscript,Asp Classic,Vbscript,我有一个网站正在ASP Classic中构建,我在一个允许用户下载文件但隐藏文件路径的脚本中遇到了一些问题 当用户在页面上时,他们将看到一个链接。链接的编码如下所示: <a href="download.asp?file=FILE-NAME-HERE" target="_blank">Download File</a> 此链接将把他们带到download.asp,在那里运行代码以获取文件并传递它。以下是我现在掌握的代码: <% const adTypeBina

我有一个网站正在ASP Classic中构建,我在一个允许用户下载文件但隐藏文件路径的脚本中遇到了一些问题

当用户在页面上时,他们将看到一个链接。链接的编码如下所示:

<a href="download.asp?file=FILE-NAME-HERE" target="_blank">Download File</a>

此链接将把他们带到download.asp,在那里运行代码以获取文件并传递它。以下是我现在掌握的代码:

<%
const adTypeBinary = 1
dim strFilePath, strFile

strFilePath = "/_uploads/private/" 
strFile = Request.QueryString("file") 

if strFile <> "" then
    'Set the content type to the specific type that you are sending.
     Response.ContentType = "application/octet-stream"
     Response.AddHeader "Content-Disposition", "attachment; filename=" & strFile

     set objStream = Server.CreateObject("ADODB.Stream")
     objStream.open
     objStream.type = adTypeBinary
     objStream.LoadFromFile(strFilePath & strFile)

    response.binarywrite objStream.Read

    objStream.close
    Set objStream = nothing

end if
%>

在上面的评论中,感谢用户oracle认证专家

有效的方法是添加“Server.MapPath”来解析文件位置

而不是使用:

objStream.LoadFromFile(strFilePath & strFile)
我把它改成:

objStream.LoadFromFile(Server.MapPath(strFilePath & strFile))

现在,链接会触发文件正确下载。

IIS是否具有该文件夹的读取权限?是的,“\u uploads/private/”文件夹的当前权限值为755。请尝试整个驱动器号+路径。您可以尝试使用解析路径,即
objStream.LoadFromFile(Server.MapPath(strFilePath&strFile))