明凯博客

关注网站技术,一个特立独行的程序员

ASP实现文件直接下载的方法

gt;Error:”&strFilename&” does not exists!”)
Response.End
end if

‘ get length of file
Set f = fso.GetFile(strFilename)
intFilelength = f.size

s.LoadFromFile(strFilename)
if err then
Response.Write(“

Error:

Unknown Error!”)
Response.End
end if

‘ send the headers to the users Browse
Response.AddHeader “Content-Disposition”,”attachment; filename=”&f.name
Response.AddHeader “Content-Length”,intFilelength
Response.CharSet = “UTF-8”
Response.ContentType = “application/octet-stream”

‘ output the file to the browser
Response.BinaryWrite s.Read
Response.Flush

‘ tidy up
s.Close
Set s = Nothing

End Function

用上面的方法比直接超链接文件地址安全的多,而且不会直接打开文件。

如果downloadFile的参数不对,可以自定义replace里面的内容,上面只是我服务器的规则。

Pages: 1 2 3

, , , ,

相关文章

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注