TXT.WORD文檔下載在本地,而不是在瀏覽器中開啟

來源:互聯網
上載者:User
word|瀏覽器|下載 <%
Response.Buffer=true
取得要下載的檔案,如果不為空白。就下載
dim url,trueurl
url="下載檔案路徑和下載檔案名稱"
   fname=Request("filename")
   if fname<>"" then
      trueurlurl=server.MapPath("/") &url
   end if
   set objFso=server.CreateObject("scripting.filesystemobject")
   set fn=objFso.GetFile(trueurl)
   flsize=fn.size
   flname=fn.name
   set fn=nothing
   set objFso=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="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 ".ASP", ".ASA", "ASPX", "ASAX", ".MDB"
        Response.Write "受保護檔案,不能下載."
        Response.End
      case else
      ContentType="appliation/octet-stream"
   end select

   Response.AddHeader "Content-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
%>

相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。