ASP儲存遠程圖片

來源:互聯網
上載者:User

記得很多的編輯器、自動採集系統都一個自動儲存遠程圖片的功能,大概原理就是利用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.google.cn/intl/zh-CN/images/logo_cn.gif"
Call SaveRemoteFile(SaveAddr,SourceURL)
%>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.