萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> java >> ASP教程:ASP保存遠程圖片

ASP教程:ASP保存遠程圖片

class="area">

記得很多的編輯器、自動采集系統都一個自動保存遠程圖片的功能,大概原理就是利用xmlhttp對象獲取圖片,然後用流對象寫入保存,參照網上的代碼,自己寫了一個,與流傳的代碼沒什麼區別!代碼如下,就一個函數:

<%
Function SaveRemoteFile(sSavePath,sRemoteFileUrl)
  On Error Resume Next
  SaveRemoteFile = False
  Dim oXML : Set oXML = Server.CreateObject("Microsoft.XMLHTTP")
  With oXML
    .Open "Get",sRemoteFileUrl,False,"",""
    .Send
    If .Status<>200 Then Exit Function
    RemoteDate = .ResponseBody
  End With
  Set oXML = Nothing
  Dim oStream : Set oStream = Server.CreateObject("Adodb.Stream")
  With oStream
    .Type = 1
    .Open
    .Write RemoteDate
    .SaveToFile sSavePath,2
    If Err.Number=0 Then SaveRemoteFile = True
    .Close()
  End With
  Set oStream = Nothing
End Function

'調用方法如下

SaveAddr=Server.MapPath("demo.gif")
SourceURL="http://www.jz265.net/intl/zh-CN/images/logo_cn.gif"
Call SaveRemoteFile(SaveAddr,SourceURL)
%>
Tag
copyright © 萬盛學電腦網 all rights reserved