保存远程图片到本地文件夹!

<%
Function saveimg(url)
	savepath="upload"
	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
	img=xmlhttp.ResponseBody
	set xmlhttp=nothing
	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=filename
End Function
%>

<%
call saveimg("http://www.baidu.com/img/bd_logo1.png")
%>

  

posted @ 2014-09-13 17:14  lyz'blog  阅读(518)  评论(0编辑  收藏  举报