新版網站
asp 強制下載函數
發布時間:2013/11/16   已被2572人閱讀    分享到:

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.adrhaerth.com/news/132.html上海網站建設公司朗晟網絡編輯,轉發請注明來源及版權歸屬。
上一篇:順利完成:asp.net 網站如何與discuz論壇同步登錄、注冊 【關閉】
下一篇:上海朗晟網絡公司2014年春節放假通知
色聚阁