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

首頁 > 編程 > ASP > 正文

利用xmlhttp和adodb.stream加緩存技術下載遠程Web文件

2024-05-04 11:05:04
字體:
供稿:網(wǎng)友

?在實際項目開發(fā)過程中,客戶有時會輸入圖像URL,其實我們只需要下載遠程圖像到本地網(wǎng)站即可,下文是錯新技術頻道小編關于利用xmlhttp和adodb.stream加緩存技術下載遠程Web文件,一起來了解一下吧!

<%
'----------遠程獲取內(nèi)容,并將內(nèi)容存在本地電腦上,包括任何文件!----------
'---------------利用xmlhttp和adodb.stream-----------------
'On Error Resume Next
'-------------------------------定義輸出格式-----------------------------
path=request("path")
if path ="" then
path="http://pcqc.86516.com/index.asp"
'這里定義的網(wǎng)址是百度,,注意一定要有文件后綴
end if

sPath = Path
if left(lcase(path),7) <> "http://" then
'-------------如果前面沒有http就是本地文件,交給LocalFile處理------------
LocalFile(path)
else
'--------------------否則為遠程文件,交給RemoteFile處理------------------
RemoteFile(Path)
end if
'Response.Write err.Description
'--------------處理函數(shù)-----------

sub LocalFile(Path)
'-------------------如果為本地文件則簡單的跳轉(zhuǎn)到該頁面-------------------
'Response.Redirect Path
Response.write "發(fā)生錯誤!"
End Sub
Sub RemoteFile(sPath)
'-------------------------處理遠程文件函數(shù)------------------------------
FileName = GetFileName(sPath)
'-------------GetFileName為把地址轉(zhuǎn)換為合格的文件名過程-------------
FileName = Server.MapPath("Cache/" & FileName)
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
'Response.Write fileName
if objFso.FileExists(FileName) Then
'--------------檢查文件是否是已經(jīng)訪問過,如是,則簡單跳轉(zhuǎn)------------
Response.Redirect "cache/" & GetFileName(path)
Else
'----------------否則的話就先用GetBody函數(shù)讀取----------------------
'Response.Write Path
t = GetBody(Path)
'-----------------用二進制方法寫到瀏覽器上--------------------------
Response.BinaryWrite t
Response.Flush
'-----------------輸出緩沖------------------------------------------
SaveFile t,GetFileName(path)
'------------------將文件內(nèi)容緩存到本地路徑,以待下次訪問-----------
End if
Set objFso = Nothing
End Sub

Function GetBody(url)
'-----------------------本函數(shù)為遠程獲取內(nèi)容的函數(shù)---------------------
'on error resume next
'Response.Write url
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
'----------------------建立XMLHTTP對象-----------------------------
With Retrieval
.Open "Get", url, False, "", ""
'------------------用Get,異步的方法發(fā)送-----------------------
.Send
'GetBody = .ResponseText
GetBody = .ResponseBody
'------------------函數(shù)返回獲取的內(nèi)容--------------------------
End With
Set Retrieval = Nothing
'response.Write err.Description
End Function

Function GetFileName(str)
'-------------------------本函數(shù)為合格化的文件名函數(shù)-------------------
str = Replace(lcase(str),"http://","")
str = Replace(lcase(str),"http://","/")
str = Replace(str,"?","")
str = Replace(str,"&","")
str = Replace(str,"/","")
str = replace(str,vbcrlf,"")
GetFileName = str
End Function

sub SaveFile(str,fName)
'-------------------------本函數(shù)為將流內(nèi)容存盤的函數(shù)-------------------
'on error resume next
Set objStream = Server.CreateObject("ADODB.Stream")
'--------------建立ADODB.Stream對象,必須要ADO 2.5以上版本---------
'objStream.Type = adTypeBinary
objStream.Type = 1
'-------------以二進制模式打開-------------------------------------
objStream.Open
objstream.write str
'--------------------將字符串內(nèi)容寫入緩沖--------------------------
'response.Write fname
'路徑注意
objstream.SaveToFile "E:/webroot/pcqc/vip/UploadFile/cache/"&fName,2
'objstream.SaveToFile "d:/cache/" & fName,adSaveCreateOverWrite
'--------------------將緩沖的內(nèi)容寫入文件--------------------------
'response.BinaryWrite objstream.Read
objstream.Close()
set objstream = nothing
'-----------------------關閉對象,釋放資源-------------------------
'response.Write err.Description
End sub

function saveimage(from,tofile)
dim geturl,objStream,imgs
geturl=trim(from)
imgs=gethttppage(geturl)'取得圖片的具休內(nèi)容的過程
Set objStream = Server.CreateObject("ADODB.Stream")'建立ADODB.Stream對象,必須要ADO 2.5以上版本
objStream.Type =1'以二進制模式打開
objStream.Open
objstream.write imgs'將字符串內(nèi)容寫入緩沖
objstream.SaveToFile server.mappath(tofile),2'-將緩沖的內(nèi)容寫入文件
objstream.Close()'關閉對象
set objstream=nothing
end function
%>

以上代碼都是錯新技術頻道小編為大家搜集的關于利用xmlhttp和adodb.stream加緩存技術下載遠程Web文件,希望對大家的學習有一定的幫助!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 安丘市| 旬邑县| 长阳| 渝中区| 平昌县| 资兴市| 砚山县| 石阡县| 绥芬河市| 松桃| 咸宁市| 太湖县| 高州市| 疏勒县| 萍乡市| 大渡口区| 科技| 广丰县| 漯河市| 岳西县| 滦南县| 张家口市| 泰和县| 泗洪县| 西乌珠穆沁旗| 大方县| 溧水县| 宜兰县| 天全县| 商城县| 通河县| 五指山市| 綦江县| 镇宁| 交城县| 克山县| 忻州市| 固阳县| 拜城县| 元阳县| 萝北县|