Download any suffix file (anti-theft chain) using AdoDb.Stream

xiaoxiao2021-03-06  18

Download any suffix file (anti-theft chain) using AdoDb.Stream

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 URLDIM FSO, FL, FLSIZEDIM DNAMEDIM OBJSTREAM, ContentType, 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 = 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 the files and download the files below you can use Download! .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 (Request.ServerVariables ("http_referer"), "http: // your domain name") = 0 Then Response.Endend IF

It is possible to prevent the chain of others.

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

New Post(0)