html中点击下载的代码怎么写

2024-11-25 22:03:55
推荐回答(2个)
回答1:

<%

function download(f,n)
'f文件全路径,n下载文件的文件名
on error resume next
Set S=CreateObject("Adodb.Stream")
S.Mode=3
S.Type=1
S.Open
S.LoadFromFile(f)
if Err.Number>0 then
Reaponse.status="404"
else
Response.ContentType="application/octet-stream"
Response.AddHeader "Content-Disposition:","Attachment;filename="&n
Range=Mid(Request.ServerVariables("HTTP_RANGE"),7)
if Range="" then
Response.BinaryWrite(S.Read)
else
S.Postion=Clng(Split(Range,"-")(0))
Response.BinaryWrite(S.Read)
end if
end if
Response.end
end function

dim filename

d=replace(request("d"),"../","")
d=replace(d,".asp",".err")
'必须防止下载asp文件。
filename="down/"&d
'response.write filename
call download(server.MapPath(filename),d)
%>

这是我用过的。下载word 等都符合你的要求,不会直接打开。

回答2: