国产探花免费观看_亚洲丰满少妇自慰呻吟_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能夠有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 元氏县| 大城县| 汶川县| 岫岩| 兴义市| 新乡县| 久治县| 大新县| 得荣县| 房产| 沐川县| 印江| 涟水县| 银川市| 鄂托克前旗| 会同县| 佛学| 阜阳市| 从江县| 安义县| 余江县| 军事| 镇平县| 富裕县| 黎川县| 镇巴县| 洛宁县| 宜川县| 宽城| 唐海县| 历史| 鹿泉市| 平陆县| 丹阳市| 舞阳县| 房山区| 辽阳县| 荔波县| 外汇| 江阴市| 敦煌市|