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

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

<%

'函数功能:把文章内容中涉及到的图片自动保存到本地服务器。(注意:请先在目录下创建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

%>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有  導航