国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

ASP實現強制圖片下載函數

2024-05-04 11:10:00
字體:
來源:轉載
供稿:網友

最近做的一個asp項目需要強制下載圖片,我在網上找了很多關于下載遠程圖片的ASP代碼,但測試結果都不行。沒辦法只好自己操刀了,有什么紕漏的地方還請大家指出。

圖片不進行處理,圖片默認是用瀏覽器打開顯示,如果希望圖片變為下載可以使用以下代碼

 

 
  1. function downloadFile(strFile) 
  2. strFilename = server.MapPath(strFile) 
  3.  
  4. Response.Buffer = True 
  5. Response.Clear 
  6.  
  7. Set s = Server.CreateObject("ADODB.Stream"
  8. s.Open 
  9.  
  10. s.Type = 1 
  11.  
  12. on error resume next 
  13.  
  14. Set fso = Server.CreateObject("Scripting.FileSystemObject"
  15. if not fso.FileExists(strFilename) then 
  16. Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>"
  17. Response.End 
  18. end if 
  19.  
  20. Set f = fso.GetFile(strFilename) 
  21. intFilelength = f.size 
  22.  
  23. s.LoadFromFile(strFilename) 
  24. if err then 
  25. Response.Write("<h1>Error: </h1>" & err.Description & "<p>"
  26. Response.End 
  27. end if 
  28.  
  29. Response.AddHeader "Content-Disposition""attachment; filename=" & f.name 
  30. Response.AddHeader "Content-Length", intFilelength 
  31. Response.CharSet = "UTF-8" 
  32. Response.ContentType = "application/octet-stream" 
  33.  
  34. Response.BinaryWrite s.Read 
  35. Response.Flush 
  36.  
  37. s.Close 
  38. Set s = Nothing 
  39. End Function 

以上所述就是本文給大家分享的函數了,希望對大家學習asp能夠有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 奉贤区| 定襄县| 怀来县| 二手房| 兰州市| 白山市| 丰县| 蓝山县| 灌云县| 上思县| 新郑市| 巫山县| 宣威市| 定结县| 米林县| 绥宁县| 龙游县| 富裕县| 九台市| 福海县| 密山市| 岳普湖县| 寿光市| 璧山县| 海兴县| 庆元县| 诸暨市| 腾冲县| 宁武县| 凉城县| 南昌县| 英山县| 嘉峪关市| 二手房| 天峨县| 正阳县| 土默特右旗| 从江县| 涞水县| 福州市| 靖州|