Download file directly with Stream

zhaozj2021-02-16  91

In the address bar of the browser, enter a URL path of a DOC or XLS or JPG file directly, then the file will be displayed directly in the browser.

And in many times we hope to pop up the download prompt directly to let the user download, what should we do? Here are two ways: 1. Set your server's IIS, make mapping for DOCs 2, set it to set it when sending it to the client, set its contentty. Detailed Description Method 2 <% response.buffer = TrueResponse.clear DIM URL DIM FSO, FL, FLSIZE DIM DNAME DIM OBJSTREAM, ContentTy, Flname, Isre, URL1 '***************************************** ************ Download file name DNAME = Trim when calling DNAME = TRIM (Request ("N")) '*************** ************************************************ DNAME <> "" "**************************** Download the server directory URL = Server.mappath ( "/") & "/" & DName '************************************************ ********** * End if set fso = server.createObject ("scripting.filesystemObject") set fl = fso.getfile (URL) FLSIZE = fl.size flname = fl.name set fl = notting set fso = Nothing%> <% Set objStream = Server.CreateObject ( "ADODB.Stream") objStream.Open objStream.Type = 1 objStream.LoadFromFile url Select Case lcase (Right (flName, 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 "case" .jpg "," jpeg "contenttype =" iMage / jpeg "case" .wav " ContentType = "Audio / WAV" case ".mp3" contenttype = "confed" case ".mpg", "MPEG" contenttype = "video / mpeg" case ".rtf"

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

New Post(0)