Automatically save the pictures involved in the content of the article to the local server

Source: Internet
Author: User
Server <%
' function function: To automatically save the pictures involved in the content of the article to the local server. (Note: Please create a tempfile directory under the directory to save the temporary picture)
' Author: Little Grey
' qq:103895
' Home: http://asp2004.net
' 2004.9.13
' Reprint or use please do not delete the above information. Thank you!

Const savepath= "tempfile/"

function Myreplace (str)
Newstr=str
Set Objregex = new REGEXP
Objregex.ignorecase = True
Objregex.global = True
Objregex.pattern = "http://(. +?) \. (jpg|gif|png|bmp) "
Set matches = Objregex.execute (str)
For the match in matches
Newstr=replace (Newstr,match.value,saveimg (Match.value))
Next
Myreplace=newstr
End Function

function saveimg (URL)
Temp=split (URL, ".")
Randomize
Rannum=int (90000*RND) +10000
Filename=year (now) &month (now), &day (now), &hour (now) &minute (now), &second (now) &ranNum& "." &temp (UBound (temp))
Set Xmlhttp=server.createobject ("Microsoft.XMLHTTP")
Xmlhttp.open "Get", Url,false
Xmlhttp.send
If xmlhttp.status<>200 Then
Saveimg= ""
Else
Img=xmlhttp. Responsebody
Set Objadostream=server.createobject ("ADODB. Stream ")
Objadostream.open ()
Objadostream.type=1
Objadostream.write (IMG)
Objadostream.savetofile (Server.MapPath ("./" &savepath&filename))
Objadostream.seteos
Set objadostream=nothing
Saveimg=savepath&filename
End If
Set xmlhttp=nothing
End Function
%>




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.