<%'传入两个参数:strFileWebPath:要下载文件所在的实际网络路径;downloadsavename:在客户端下载提示时保存的文件名 Function DownLoadFile(strFileWebPath,downloadsavename) downloadshowname=downloadsavename strFilename = server.MapPath(strFileWebPath) Response.Buffer = True Response.Clear Set Obj = Server.CreateObject("ADODB.Stream") Obj.Open Obj.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 Fso = fso.GetFile(strFilename) intFilelength = Fso.size Obj.LoadFromFile(strFilename) if err then Response.Write("<h1>Error: </h1>" & err.Description & "<p>") Response.End end if Response.AddHeader "Content-Disposition", "attachment; filename=" &downloadshowname Response.AddHeader "Content-Length", intFilelength Response.CharSet = "UTF-8" Response.ContentType = "application/octet-stream" Response.BinaryWrite Obj.Read Response.Flush Obj.Close Set Obj = Nothing End Function%>
<%'传入两个参数:strFileWebPath:要下载文件所在的实际网络路径;downloadsavename:在客户端下载提示时保存的文件名 Function DownLoadFile(strFileWebPath,downloadsavename) downloadshowname=downloadsavename strFilename = server.MapPath(strFileWebPath) Response.Buffer = True Response.Clear Set Obj = Server.CreateObject("ADODB.Stream") Obj.Open Obj.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 Fso = fso.GetFile(strFilename) intFilelength = Fso.size Obj.LoadFromFile(strFilename) if err then Response.Write("<h1>Error: </h1>" & err.Description & "<p>") Response.End end if Response.AddHeader "Content-Disposition", "attachment; filename=" &downloadshowname Response.AddHeader "Content-Length", intFilelength Response.CharSet = "UTF-8" Response.ContentType = "application/octet-stream" Response.BinaryWrite Obj.Read Response.Flush Obj.Close Set Obj = Nothing End Function if request("action")="create" then DownLoadFile "1.text","a.txt" response.End() end if %> <html> <head><title></title> </head> <body> dgdgdg <form> <input name="a" type="button" value="download" onclick="javascript:window.location='?action=create';" /> </form> sdfsdfsfsd </body> </html>