|
利用ADODB.Stream使用浏览器下载服务器文件 |
〖编辑:Cloudy | 浏览:人次〗 |
download.asp?file=相对路径的文件 就可以把这个文件下载下来 <% call downloadFile(replace(replace(Request("file"),"\",""),"/","")) 4 5 Function downloadFile(strFile) ' make sure you are on the latest MDAC version for this to work ' ------------------------------------------------------------- ' get full path of specified file 11 strFilename = server.MapPath(strFile) ' clear the buffer 15 Response.Buffer = True Response.Clear ' 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(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" ' output the file to the browser Response.BinaryWrite s.Read Response.Flush ' tidy up s.Close Set s = Nothing End Function %> |
录入时间:2007-03-12 20:50:03 [打印本页]
[关闭窗口]
[返回顶部] |
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。 |
|
|