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? There are two methods here: 1. Set the IIS of your server, make mapping of the suffix names such as DOC 2, set its contenttype when sending to the client
Detailed description 2
<% Response.buffer = truerenponse.clear
DIM URL DIM FSO, FL, FLSIZE DIM DNAME DIM OBJSTREAM, ContentTy, Flname, Isre, URL1 '************************************************ *************** Download file name DNAME = Trim (Request ("N")) '************** *********************************************************** ** if DName <> "" THEN '******************************* 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 = Nothing 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 ".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 =" text / html "Case" .txt "ContentType =" text / plain "Case Else ContentType =" application / octet-stream "End SelectResponse .Addic-disposition "," attachment; filename = "& flname response.addheader" content-length ", FLSIZE
Response.charset = "UTF-8" response.contentType = ContentType
Response.binarywrite objstream.read response.flush response.clear () objstream.close set objstream = Nothing
%>
Use the following things to Download.ASP and you can use Download! to download the same directory File.doc!
But here has a problem is that it is not safe in the URL directly, so the solution should save the path of file.doc to the database, and get the path after the database is found.
In the forefront of this program, if you add a judgment:
If INSTR ("http_referer"), "http: // Your Domain Name") = 0 The response.Endendend IF can prevent someone else's chain