call download(server.mappath("./test.jpg"))
Function download(File)
temp = Split(File, "/")
filename = temp(UBound(temp))
Set s = CreateObject("adodb.stream")
s.mode = 3
s.Type = 1
s.Open
s.loadfromfile(File)
data = s.Read
If IsNull(data) Then
response.Write "空"
Else
response.Clear
Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachment; filename=" & filename
response.binarywrite(data)
End If
Set s = Nothing
End Function
Function download(File)
temp = Split(File, "/")
filename = temp(UBound(temp))
Set s = CreateObject("adodb.stream")
s.mode = 3
s.Type = 1
s.Open
s.loadfromfile(File)
data = s.Read
If IsNull(data) Then
response.Write "空"
Else
response.Clear
Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachment; filename=" & filename
response.binarywrite(data)
End If
Set s = Nothing
End Function
本文介绍了一个使用ASP编写的函数,该函数可以从服务器下载指定路径的文件,并将其作为附件提供给客户端。具体步骤包括:获取文件路径、创建ADODB流对象、设置流模式与类型、加载文件内容并读取数据等。
1万+

被折叠的 条评论
为什么被折叠?



