<%
'保存远程图片
'========================================================================================

function getHTTPPage(url)
	on error resume next
	dim httpobjs
	set httpobjs=server.createobject("Microsoft.XMLHTTP")'使用xmlhttp的方法来获得图片的内容
	httpobjs.open "GET",url,false
	httpobjs.send()
	if httpobjs.readystate<>4 then 
		exit function
	end if
	getHTTPPage=httpobjs.responseBody
	set httpobjs=nothing
	if err.number<>0 then err.Clear 
end function
function saveimage(from,tofile)
	dim geturl,objStream,imgs
	geturl=trim(from)
	imgs=gethttppage(geturl)'取得图片的具休内容的过程
	Set objStream = Server.CreateObject("ADODB.Stream")'建立ADODB.Stream对象，必须要ADO 2.5以上版本
	objStream.Type =1'以二进制模式打开
	objStream.Open
	objstream.write imgs'将字符串内容写入缓冲
	objstream.SaveToFile tofile,2'-将缓冲的内容写入文件
	objstream.Close()'关闭对象
	set objstream=nothing
end function

function saveAndReplaceRemoteImg(getContent,savePath,daysPath,imgPreName)
	retstr=initStr(getContent)
	arrimg=split(retstr,"||")'分割字串，取得里面地址列表
	allimg=""
	newimg=""	
	for i=1 to ubound(arrimg)
		if arrimg(i)<>"" and instr(allimg,arrimg(i))<1 then'看这个图片是否已经下载过
			fname=cstr(i&mid(arrimg(i),instrrev(arrimg(i),".")))
			call saveimage(arrimg(i),savePath&imgPreName&"_"&fname)'保存地址的函数，过程见上面
			allimg=allimg&"||"&arrimg(i)'把保存下来的图片的地址串回起来，以确定要替换的地址
			newimg=newimg&"||"&SiteUrl&"/"&Imgsavedir&"/"&dayspath&"/"&imgPreName&"_"&fname'把本地的地址串回起来
		end if
	next
	arrnew=split(newimg,"||")'取得原来的图片地址列表
	arrall=split(allimg,"||")'取得已经保存下来的图片的地址列表
	for i=1 to ubound(arrnew)'执行循环替换原来的地址
		getContent=replace(getContent,arrall(i),arrnew(i))
	next
	saveAndReplaceRemoteImg=getContent
end function
%>