ASP中计算文件被下载的次数

来源:百度知道 编辑:UC知道 时间:2024/06/14 20:05:59
我想计算文件被下载的次数
点击下载按钮时
<a href="<%=rs("filepath")%>" ><img src="images/download.gif" border="0" onClick="downtimesadd()"></a>
调用函数downtimesadd()把表中的次数加一
<script language=vbscript>
<%sub downtimesadd()
set rs2 = server.CreateObject ("Adodb.recordset")
sql2="update downtimes set downtimes=(downtimes+1) where filename="&request("filename")
rs2.open sql2,conn,1,1
set rs2=nothing
end sub
%>
</script>

downtimes表含两个字段filename(文件名称)、downtimes(下载次数)
那DownLoad这个页面该怎么写?谢谢啊。

这样是不行的!下面的代码你把服务器的的执行代码和客户端搞混乱了题!
<script language=vbscript>
<%sub downtimesadd()
set rs2 = server.CreateObject ("Adodb.recordset")
sql2="update downtimes set downtimes=(downtimes+1) where filename="&request("filename")
rs2.open sql2,conn,1,1
set rs2=nothing
end sub
%>
</script>
你可以这样来实现
点击下载按钮时
<a href="download.asp?id=<%=rs("id")%>" ><img src="images/download.gif" border="0"></a>
在download.asp中:
<%
set rs2 = server.CreateObject ("Adodb.recordset")
sql2="update downtimes set downtimes=(downtimes+1) where id="&request("id")
rs2.open sql2,conn,1,1
set rs2=nothing
Response.Redirect rs("filepath")
%>
因为我不知道你的数据库的结构,但我假设你的数据库中存在id字段。

VBSCRIPT我用的不多,,但好象你这样用是没有用样的。。

你可以去这样做,下载链接的地方你可以改做DownLoad.Asp?I