ASP save remote Images

Source: Internet
Author: User

Remember that many editors and automatic collection systems use the function of automatically saving remote images. The general principle is to use the XMLHTTP object to retrieve images, and then write and save images with stream objects. Refer to the online code, I wrote one by myself, which is no different from the circulating code! The Code is as follows:

<%
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
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
Set ostream = nothing
End Function
'Call method:
Saveaddr = server. mappath ("demo.gif ")
Sourceurl = "http://www.google.cn/intl/zh-CN/images/logo_cn.gif"
Call saveremotefile (saveaddr, sourceurl)
%>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.