我是用超链接来做的(如:<a href="http://127.0.0.1/a.rar">)
点击后,如果是.rar(压缩)文件就没什么问题,能正常下载,但如果是.exe的话,虽出现了下载提示,但同时也在执行.exe该文件,如果是碰到.txt的话,就直接是在浏览器上显示该文件内容了,不能下载了。
请教一下,像这种下载是怎样来实现的呢?
像还有很多网站上提示的下载还要指定下载工具,像这种情况又是怎样来实现的呢?
// 2006-5-10 天涯听雨 原创
Sub 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", "attachment; filename=" &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 Sub
DonwnFileName=Trim(Request.QueryString("DonwnFileName"))
Call DownLoadFile(DonwnFileName)