ASP實現(xiàn)強制圖片下載函數(shù)
更新時間:2015年05月18日 11:39:27 投稿:hebedich
最近做的一個asp項目需要強制下載圖片,我在網(wǎng)上找了很多關(guān)于下載遠程圖片的ASP代碼,但測試結(jié)果都不行。沒辦法只好自己操刀了,有什么紕漏的地方還請大家指出。
圖片不進行處理,圖片默認是用瀏覽器打開顯示,如果希望圖片變?yōu)橄螺d可以使用以下代碼
function downloadFile(strFile) strFilename = server.MapPath(strFile) Response.Buffer = True Response.Clear Set s = Server.CreateObject("ADODB.Stream") s.Open s.Type = 1 on error resume next Set fso = Server.CreateObject("Scripting.FileSystemObject") if not fso.FileExists(strFilename) then Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>") Response.End end if Set f = fso.GetFile(strFilename) intFilelength = f.size s.LoadFromFile(strFilename) if err then Response.Write("<h1>Error: </h1>" & err.Description & "<p>") Response.End end if Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name Response.AddHeader "Content-Length", intFilelength Response.CharSet = "UTF-8" Response.ContentType = "application/octet-stream" Response.BinaryWrite s.Read Response.Flush s.Close Set s = Nothing End Function
以上所述就是本文給大家分享的函數(shù)了,希望對大家學習asp能夠有所幫助。
您可能感興趣的文章:
- ASP 時間函數(shù)及如何獲取服務(wù)器時間的寫法
- Asp Split函數(shù)之使用多個分割符的方法
- asp與js的類型轉(zhuǎn)換函數(shù)介紹
- asp中的Rnd 函數(shù)
- ASP轉(zhuǎn)換格林威治時間函數(shù)DateDiff()應(yīng)用
- ASP移動文件函數(shù)movefile權(quán)限不足的替代方法
- ASP中實現(xiàn)的URLEncode、URLDecode自定義函數(shù)
- asp實現(xiàn)獲取MSSQL數(shù)據(jù)庫表指定條件行數(shù)的函數(shù)
- asp中實現(xiàn)清除html的函數(shù)
- asp實現(xiàn)截取字符串函數(shù)
- ASP函數(shù)大全解析
相關(guān)文章
asp中去除內(nèi)容HTML標簽的三個function函數(shù)
asp中去除內(nèi)容HTML標簽的三個function函數(shù)...2007-03-03ASP中字符與數(shù)字內(nèi)置操作函數(shù)整理
在ASP中,預(yù)定義了許多函數(shù),可以幫助我們簡化代碼、提高開發(fā)效率,本文將介紹一些常用的ASP字符與數(shù)字內(nèi)置操作函數(shù),以便開發(fā)人員更加方便、快速地創(chuàng)建 Web 應(yīng)用程序,2023-12-12P3P 和 跨域 (cross-domain) cookie 訪問(讀取和設(shè)置)
在IE 里面跨域去設(shè)置 cookie跨域的實現(xiàn),嘗試了n中方法都不行,查了一下資料,可以通過設(shè)置header中的p3p值來實現(xiàn),真不錯:)2009-06-06asp中response.write(''中文'')或者js中文亂碼問題
這篇文章主要介紹了asp中response.write('中文')或者js中文亂碼問題,有時候我們需要輸出js也會出現(xiàn)亂碼,這里給出了幾個解決方法,需要的朋友可以參考下2020-03-03