bestlong 怕失憶論壇

 

 

搜索
bestlong 怕失憶論壇 論壇 MS WebForm Tech ASP 強制下載檔案的程式(不會在網頁中開啟) ...
查看: 13942|回復: 0
go

ASP 強制下載檔案的程式(不會在網頁中開啟) [複製鏈接]

Rank: 9Rank: 9Rank: 9

1#
發表於 2006-9-12 16:08 |只看該作者 |倒序瀏覽 |打印
  1. <%
  2. ' download.asp
  3. Response.Buffer = True
  4. Dim strFilePath, strFileSize, strFileName
  5. Const adTypeBinary = 1
  6. strFilePath = Request.QueryString("File")
  7. strFileSize = Request.QueryString("Size")
  8. strFileName = Request.QueryString("Name")
  9. Response.Clear
  10. Set objStream = Server.CreateObject("ADODB.Stream")
  11. objStream.Open
  12. objStream.Type = adTypeBinary
  13. objStream.LoadFromFile server.mappath(strFilePath)
  14. strFileType = lcase(Right(strFileName, 4))
  15. Select Case strFileType
  16. Case ".asf"
  17.   ContentType = "video/x-ms-asf"
  18. Case ".avi"
  19.   ContentType = "video/avi"
  20. Case ".doc"
  21.   ContentType = "application/msword"
  22. Case ".zip"
  23.   ContentType = "application/zip"
  24. Case ".xls"
  25.   ContentType = "application/vnd.ms-excel"
  26. Case ".gif"
  27.   ContentType = "image/gif"
  28. Case ".jpg", "jpeg"
  29.   ContentType = "image/jpeg"
  30. Case ".wav"
  31.   ContentType = "audio/wav"
  32. Case ".mp3"
  33.   ContentType = "audio/mpeg3"
  34. Case ".mpg", "mpeg"
  35.   ContentType = "video/mpeg"
  36. Case ".rtf"
  37.   ContentType = "application/rtf"
  38. Case ".htm", "html"
  39.   ContentType = "text/html"
  40. Case ".asp"
  41.   ContentType = "text/asp"
  42. Case Else
  43.   ContentType = "application/octet-stream"
  44. End Select
  45. Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
  46. Response.AddHeader "Content-Length", strFileSize
  47. Response.Charset = "UTF-8"
  48. Response.ContentType = ContentType
  49. Response.BinaryWrite objStream.Read
  50. Response.Flush
  51. objStream.Close
  52. Set objStream = Nothing
  53. %>
複製代碼


用 download.asp?File=檔名 就會直接出現檔案下載對話框
我是雪龍
http://blog.bestlong.idv.tw
http://www.bestlong.idv.tw
‹ 上一主題|下一主題

Archiver|怕失憶論壇

GMT+8, 2024-5-2 06:05 , Processed in 0.008486 second(s), 10 queries .

Powered by Discuz! X1.5

© 2001-2010 Comsenz Inc.