asp 强制下载函数

2013/11/16 已被2839人阅读

当前位置:首页>新闻中心>技术关注【关闭】

ASP 代码:
<%
========调用========


downloadFile("test/test.mdb")

---Down File---
Function downloadFile(strFile)
get full path of specified file
strFilename = server.MapPath(strFile)
Response.Buffer = True
Response.Clear
Set s = Server.CreateObject("ADODB.Stream")
s.Open
s.Type = 1
on error resume next
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("

Error:

" & strFilename & " does not exist

")
Response.End
end if
Set f = fso.GetFile(strFilename)
intFilelength = f.size
s.LoadFromFile(strFilename)
if err then
Response.Write("

Error:

" & err.Description & "

")
Response.End
end if
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite s.Read
Response.Flush
s.Close
Set s = Nothing
End Function
%>

预约洽谈

多一份方案,多一个参考,预约我们的商务面对面沟通,总有益处 周一至周五,9:00-18:00    咨询热线:021-3100 6558 24小时热线:15900965330

我要预约
电话咨询 在线沟通 QQ咨询 微信聊天