|
发表于 2010-10-18 21:19:04
|
显示全部楼层
|阅读模式
来自 中国–河北–张家口
- <% FunctIon DownloadFIle(StrFIle)
- StrFIlename=StrFIle
- Resp**e.Buffer=True
- Resp**e.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
- From_Url=Cstr(Request.ServerVarIables("HTTP_REFERER"))
- Serv_Url=Cstr(Request.ServerVarIables("SERVER_NAME"))
- If MId(From_Url,8,len(Serv_Url)) <> Serv_Url Then
- Resp**e.WrIte "该文件不存在或者已经删除."
- Resp**e.End
- End If
- Resp**e.RedIrect Request.ServerVarIables("HTTP_REFERER")
- Resp**e.End
- End If
- FileExt=MId(StrFIlename,InStrRev(StrFIleName, ".")+1)
- Select Case UCase(FIleExt)
- Case "ASP", "ASA", "ASPX", "ASAX", "MDB", "PHP", "JSP", "SHTML", "HTML", "HTM", "TV", "DATA"
- From_Url=Cstr(Request.ServerVarIables("HTTP_REFERER"))
- Serv_Url=Cstr(Request.ServerVarIables("SERVER_NAME"))
- If MId(From_Url,8,len(Serv_Url)) <> Serv_Url Then
- Resp**e.WrIte "该文件不存在或者已经删除."
- Resp**e.End
- End If
- Resp**e.RedIrect Request.ServerVarIables("HTTP_REFERER")
- Resp**e.End
- End Select
- Set F=Fso.GetFIle(StrFIlename)
- IntFIlelength=F.SIze
- s.LoadFromFIle(StrFIlename)
- If Err Then
- From_Url=Cstr(Request.ServerVarIables("HTTP_REFERER"))
- Serv_Url=Cstr(Request.ServerVarIables("SERVER_NAME"))
- If MId(From_Url,8,len(Serv_Url)) <> Serv_Url Then
- Resp**e.WrIte "该文件数据不完整或许已损坏."
- Resp**e.End
- End If
- Resp**e.RedIrect Request.ServerVarIables("HTTP_REFERER")
- Resp**e.End
- End If
- Set Upload=Server.CreateObJect("PersIts.Upload")
- If Upload Is Nothing Then
- Resp**e.AddHeader "Content-DIsposItIon","attachment; FIlename="&F.Name
- Resp**e.AddHeader "Content-Length",IntFilelength
- Resp**e.CharSet="UTF-8"
- Resp**e.ContentType="application/x-download"
- Resp**e.BinaryWrite S.Read
- Resp**e.Flush
- S.Close
- Set s=NothIng
- Else
- Upload.SendBinary StrFIlename,True,"application/x-download",False
- End If
- End FunctIon
- %>
复制代码 调用
<%Call DownloadFIle("下载地址")%> |
|