把文章内容中涉及到的图片自动保存到本地服务器

 1   
 2const savepath="tempfile/" 
 3
 4function myreplace(str)   
 5newstr=str   
 6set objregEx = new RegExp   
 7objregEx.IgnoreCase = true   
 8objregEx.Global = true   
 9objregEx.Pattern = " http://(.+?)\\.(jpg|gif|png|bmp )"   
10set matches = objregEx.execute(str)   
11for each match in matches   
12newstr=replace(newstr,match.value,saveimg(match.value))   
13next   
14myreplace=newstr   
15end function 
16
17function saveimg(url)   
18temp=split(url,".")   
19randomize   
20ranNum=int(90000*rnd)+10000   
21filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&temp(ubound(temp))   
22set xmlhttp=server.createobject("Microsoft.XMLHTTP")   
23xmlhttp.open "get",url,false   
24xmlhttp.send   
25if xmlhttp.status<>200 then   
26saveimg=""   
27else   
28img=xmlhttp.ResponseBody   
29set objAdostream=server.createobject("ADODB.Stream")   
30objAdostream.Open()   
31objAdostream.type=1   
32objAdostream.Write(img)   
33objAdostream.SaveToFile(server.mappath("./"&savepath&filename))   
34objAdostream.SetEOS   
35set objAdostream=nothing   
36saveimg=savepath&filename   
37end if   
38set xmlhttp=nothing   
39end function   
Published At
Categories with Web编程
Tagged with
comments powered by Disqus