<%
函数功能:把文章内容中涉及到的图片自动保存到本地服务器。(注意:请先在目录下创建tempfile目录,用来保存临时图片)
作者:小灰
qq:103895
主页:http://asp2004.net
2004.9.13
转载或使用请不要删除上面这些信息。谢谢!
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
%>