求asp制作文件下载及统计下载次数制作
发布网友
发布时间:2024-02-20 10:26
我来回答
共2个回答
热心网友
时间:2024-12-04 10:46
你只要传递这个参数FileName = Request.QueryString( "FileName ")进来就OK了。
<%
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
response.write "非法链接! " '防止盗链
response.end
end if
Function GetFileName(longname) '/folder1/folder2/file.asp=> file.asp
while instr(longname, "/ ")
longname = right(longname,len(longname)-1)
wend
GetFileName = longname
End Function
Dim Stream
Dim Contents
Dim FileName
Dim TrueFileName
Dim FileExt
Const adTypeBinary = 1
FileName = Request.QueryString( "FileName ")
if FileName = " " Then
Response.Write "无效文件名! "
Response.End
End if
FileExt = Mid(FileName, InStrRev(FileName, ". ") + 1)
Select Case UCase(FileExt)
Case "ASP ", "ASA ", "ASPX ", "ASAX ", "MDB "
Response.Write "非法操作! "
Response.End
End Select
Response.Clear
if lcase(right(FileName,3))= "gif " or lcase(right(FileName,3))= "jpg " or lcase(right(FileName,3))= "png " then
Response.ContentType = "image/* " '对图像文件不出现下载对话框
else
Response.ContentType = "application/ms-download "
end if
Response.AddHeader "content-disposition ", "attachment; filename= " & GetFileName(Request.QueryString( "FileName "))
Set Stream = server.CreateObject( "ADODB.Stream ")
Stream.Type = adTypeBinary
Stream.Open
' 'if lcase(right(FileName,3))= "rar " then '设置pdf类型文件目录
TrueFileName = "../admin/upsoft/ "& FileName
' 'end if
Stream.LoadFromFile Server.MapPath(TrueFileName)
' 'While Not Stream.EOS
' 'Response.BinaryWrite Stream.Read(1024 * 64)分64块,下载,这个去掉就可以下多大都可以,加上好像不能超过5M.
' 'Wend
Stream.Close
Set Stream = Nothing
Response.Flush
Response.End
%>
下载次数
download.asp?id=要下载文件的ID编号
<%
'连接数据库,代码根据自己的数据库写
set cn = Server.CreateObject("ADODB.connection")
cn.open...
'读取id=request("id")的文件信息
sql = "select * from downfile where id = "&request("id")
set rs = Server.CreateObject("ADODB.Recordset")
rs.open sql,cn,3,1
'如果文件不存在
if rs.EOF then
response.redirect("下载错误信息页面")
'如果文件存在,读出下列数据
else
filepath = rs("filepath") '要下载文件的真实地址
filedowns = Cint(rs("filedowns")) '要下载文件已经被下载过的次数
end if
rs.close
set rs = nothing
cn.close
set cn = nothing
'将文件下载次数加1
filedowns = filedowns+1
'将新的下载次数更新入数据库,如果需要可以连同日期时间一起存起来
set cn = ....
...update
'转到要下载文件的地址
response.redirect(filepath)
%>
我对ASP也不是很了解,这些也都是在网上找的,觉得不错,未经测试,你试下,看怎样。。。。。。
热心网友
时间:2024-12-04 10:46
你可以去百度视频找 asp教学
有很多够你慢慢看的了
也可以去找教学光盘下载来看
自己学习吧