Use AdoDb.Stream to download server files using your browser

xiaoxiao2021-03-06  99

Download.asp? file = file with relative path

You can download this file.

<% Call Downloadfile (Replace (Request ("File"), "" / "," "," / ",")) Function Downloadfile (Strfile) 'Make Sure You Are On The Latest MDAC Version for this to THIS Work '----------------------------------------------- ------------- 'Get Full Path of Specified File StrfileName = Server.mappath (Strfile)' Clear The Buff 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 ("

error: " & strfilename & "does not exist

") response.end end if 'get length of file set f = fso.getfile (StrfileName) INTFILENGTH = f.size s.loadfromfile (strfilename) if Err the response.write ("

error: " & err.description & "

") response.end endiffs 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%>

转载请注明原文地址:https://www.9cbs.com/read-104305.html

New Post(0)