把文章内容中涉及到的图片自动保存到本地服务器
发布时间:2006-10-14 3:17:08   收集提供:gaoqian

<%
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 each 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
%>

 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50