|
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="mdb.asp"-->
<!--#include file="inc/WFile.asp"-->
<%
fileid=request.querystring("id")
'防盗链
if session(fileid)<>"canload" then 'session是通过点击下载连接产生的,点击才会产生这个session
response.write "请勿盗链本站内容!!!!<br>"&vbcrlf
response.write "请从<a href=""http://www.zhi2xun.cn/files/"">列表首页</a>下载本文件;<br>"&vbcrlf
response.write "若找不到文件,请使用搜索功能;<br>"&vbcrlf
response.write "非常感谢您的访问。"&vbcrlf
response.end
end if
Dim Stream
Dim Contents
Dim FileName
Dim FileExt
Const adTypeBinary = 1
'下面代码从数据库提取文件信息
sql="select Title,FileUrl from Files WHERE id="&fileid
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
FileName=rs(1)
fileexc=mid(FileName,instrrev(FileName,"."))
name=rs(0)&fileexc
tit=rs("Title")
rs.close
set rs=nothing
'提取文件信息结束
' 下载这个文件
Response.Clear
Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition", "attachment; filename="&name
Set Stream = server.CreateObject("ADODB.Stream")
Stream.Type = adTypeBinary
Stream.Open
Stream.LoadFromFile Server.MapPath(FileName)
While Not Stream.EOS
Response.BinaryWrite Stream.Read(1024 * 64)
Wend
Stream.Close
Set Stream = Nothing
'下面仅仅是统计代码
m_msg="→ 来自<font color=red>"&request.servervariables("REMOTE_ADDR")&"</font>的访客在<font color=red>"&now()&"</font>下载了<font color=red>"&tit&"</font><br />"
call writeF(server.mappath("logs.asp"),m_msg) '下载记录写入文件
if arii<>"yes" then
response.cookies("user")(fileid)="yes"
response.Cookies("user").Expires=DateAdd("d", 1, now())
sql="update Files Set Download=Download+1 where id="&fileid
conn.execute sql
end if
'统计结束
conn.close
set conn=nothing
Response.Flush
Response.End
%> |
|