By default, click to download PDF and other files instead of opening in the browser.

xiaoxiao2021-03-06  40

<% Dim StreamDim ContentsDim FileNameDim FileExtConst adTypeBinary = 1FileName = Request.QueryString ( "FileName") if FileName = "" Then Response.Write "Invalid file name." Response.EndEnd if 'do not want to download the following files FileExt = Mid ( FileName, Instrrev (FileName, ") 1) Select Case Ucase (FileExt) Case" ASP "," ASA "," ASPX "," ASAX "," The MDB "Response.write" protected file, cannot be downloaded. "Response.EndEnd Select 'download the file Response.ClearResponse.ContentType =" application / octet-stream "Response.AddHeader" content-disposition "," attachment; filename = "& FileNameSet Stream = server.CreateObject (" ADODB.Stream " ) Stream.Type = adTypeBinaryStream.OpenStream.LoadFromFile Server.MapPath (FileName) While Not Stream.EOS Response.BinaryWrite Stream.Read (1024 * 64) WendStream.CloseSet Stream = NothingResponse.FlushResponse.End%> use: download.asp? FileName = / files / my.doc puts your DOC files under the root directory files, you can also put it else else.

Such as: Click to download the Word document

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

New Post(0)