文件代码。(该代码为转载代码)
<%@ Language=VBScript %>
<%
Dim filename
filename = Trim(Request("filename"))
if filename<>"" and not isnull(filename) then filename=Replace(Replace(filename,"/",""),"\","")
call downloadFile(filename)
Function downloadFile(strFile)
strFilename = server.MapPath(strFile)
Response.Buffer = True
Response.Clear
Set s = Server.CreateObject("ADODB.Stream")
s.Open
s.Type = 1
' load in the file
on error resume next
' check the file exists
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")
Response.End
end if
' get length of file
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
' send the headers to the users browser
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 Function
%>
顶。。。。。。。。。。。。。。
to 一刺:
你的方法虽然有用,但是调用的是ie中另存为的功能。如果附件为操作系统未识别的文件类型,另存的时候可能导致文件后缀名改掉。另外还有弹出的对话框也是另存的窗口,最下面还有选择语言的项。
在ie中选中附件的时候,右键单击弹出菜单中有目标另存为一项,不知道大家能不能做到象这样的功能。