新版网站
asp 强制下载函数
发布时间:2013/11/16   已被3967人阅读    分享到:

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("<h1>Error:</h1>" & strFilename & " does not exist<p>")
Response.End
end if
Set f = fso.GetFile(strFilename)
intFilelength = f.size
s.LoadFromFile(strFilename)
if err then
Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
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
%>

本文分享地址:http://www.cn7080.com/news/132.html上海网站建设公司朗晟网络编辑,转发请注明来源及版权归属。
上一篇:顺利完成:asp.net 网站如何与discuz论坛同步登录、注册 【关闭】
下一篇:上海朗晟网络公司2014年春节放假通知