楼上说得对,以下是ASP的代码 <%filename="yourpath" ' create stream Set s = Server.CreateObject("ADODB.Stream") s.Open ' Set as binary 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(Filename) then 'Err = filename & " 此文件未找到!" Response.Write("<h1>Error:</h1>" & Filename & " 此文件未找到!<p>") Response.End end if ' get length of file Set f = fso.GetFile(Filename) intFilelength = f.size s.LoadFromFile(Filename) if err then 'Err = err.Description 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=" & sourcefilename 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 %>
<%filename="yourpath"
' create stream
Set s = Server.CreateObject("ADODB.Stream")
s.Open ' Set as binary
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(Filename) then
'Err = filename & " 此文件未找到!"
Response.Write("<h1>Error:</h1>" & Filename & " 此文件未找到!<p>")
Response.End
end if ' get length of file
Set f = fso.GetFile(Filename)
intFilelength = f.size s.LoadFromFile(Filename)
if err then
'Err = err.Description
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=" & sourcefilename
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
%>