Download any type of file

xiaoxiao2021-03-06  68

<% Response.buffer = truerenponse.clear

'Get the absolute position of the file to download on the server DLFILE = TRIM (Request ("DLFile")) IF DLFILE <> ""1 fileurl = server.mappath (dlfile) Else Response.end endiff

'Creating Myfso, using FSO component set myfso = server.createObject ("scripting.filesystemObject") set f = myfso.getfile (fileurl)' Define FSO object f fsize = f.size 'file size fname = f.name' file name Set f = nothing 'release f set myfso = nothing' release myfso

'Using AdoDb.Stream Components Set MyStream = Server.createObject ("AdoDb.Stream") MyStream.Openmystream.Type = 1MYSTREAM.LOADFROMFILE FILEURL

'Read file types, let system identify, to save different types of files. Select Case Lcase (Right (FNAME, 4)) Case ".asf" contenttype = "video / x-ms-asf" case ".avi" contenttype = "video / avi" case ".doc" contenttype = "Application / MSWord "Case" .zip "contenttype =" Application / ZIP "case" .xls "contenttype =" Application / VND.ms-Excel "case" .gif "ContentType =" image / gif ".jpg", "jpeg" ContentType = "image / jpeg" case ".wav" contenttype = "AUDIO / WAV" case ".mp3" contentty = "AUDIO / MPEG3" CASE ". MPG", "MPEG" contenttype = "VIDEO / MPEG" case ". RTF "ContentType = Application / RTF" Case ".htm", "HTML" Contenttype = "textTy" .asp "contenttype =" text / html "case" .txt "contenttype =" text / plain "CASE Else ContentType = "Application / Oct-stream" end SELECT

'Download Response.AddHeader "Content-Disposition", "attachment; filename =" & fNameResponse.AddHeader "Content-Length", fsizeResponse.Charset = "UTF-8" Response.ContentType = ContentTypeResponse.BinaryWrite MyStream.ReadResponse.Flush' release MyStreamMyStream.closeset mystream = Nothing%> XXX

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

New Post(0)