问题描述:
在软件信息上有一个下载按钮:
<a href="down?filename=<%=rs("filename")%>"><img src=images/download.gif border=0></a>
<!--#include file="conn"-->
<%
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
set rs = server.CreateObject ("Adodb.recordset")
sql="select * from upfile where filename="&request("filename")
rs.open sql,conn,1,1
Response.Redirect rs("filepath")
%>
filepath一般是“XXX.mp3”或“XXX.wma”、“XXX.doc”、“XXX”这样的名称,当点击下载按钮后,浏览器不显示下载对话框,而是直接在浏览器中播放或是显示这些文档或图片。请问有没有什么办法,不让浏览器调用本机播放器播放这些影音文件。当然,右键“目标另存为”可以下载,但是这样就不能计算文件的下载次数了,有两全其美的办法么?
解析:
Function downloadFile(strFile)
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>文件不存在<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", "attachmentfilename=" &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
看这个函数能帮到你吗
把下面的代码保存为download.asp,然后把下载链接改成<a href="Download.asp?FileName=***.rm">下载视频</a>就可以了:<%FileName=Request.Querystring("FileName")
Function GetFileName(longname)
while instr(longname,"/")
longname=right(longname,len(longname)-1)
wend
GetFileName=longname
End Function
Const adTypeBinary=1
FileExt=Mid(FileName,InStrRev(FileName,".")+1)
Response.Clear
Response.AddHeader "content-disposition","attachmentfilename="&GetFileName(FileName)
Set Stream=server.CreateObject("ADODB.Stream")
Stream.Type=adTypeBinary
Stream.Open
'这里把DownloadFiles改成下载文件所在文件夹与本页的相对路径
TrueFileName="DownloadFiles/"&FileName
Stream.LoadFromFile Server.MapPath(TrueFileName)
While Not Stream.EOS
Response.BinaryWrite Stream.Read(1024*64)
Wend
Stream.Close
Set Stream=Nothing
Response.Flush
Response.End%>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)