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

 
  1. <%
  2.     const savepath="tempfile/"
  3.     function myreplace(str)
  4.     newstr=str
  5.     set objregEx = new RegExp
  6.     objregEx.IgnoreCase = true
  7.     objregEx.Global = true
  8.     objregEx.Pattern = "http://(.+?)/.(jpg|gif|png|bmp)"
  9.     set matches = objregEx.execute(str)
  10.     for each match in matches
  11.     newstr=replace(newstr,match.value,saveimg(match.value))
  12.     next
  13.     myreplace=newstr
  14.     end function
  15.     function saveimg(url)
  16.     temp=split(url,".")
  17.     randomize
  18.     ranNum=int(90000*rnd)+10000
  19.     filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum"."&temp(ubound(temp))
  20.     set xmlhttp=server.createobject("Microsoft.XMLHTTP")
  21.     xmlhttp.open "get",url,false
  22.     xmlhttp.send
  23.     if xmlhttp.status<>200 then
  24.         saveimg=""
  25.     else
  26.         img=xmlhttp.ResponseBody
  27.         set objAdostream=server.createobject("ADODB.Stream")
  28.         objAdostream.Open()
  29.         objAdostream.type=1
  30.         objAdostream.Write(img)
  31.         objAdostream.SaveToFile(server.mappath("./"&savepath&filename))
  32.         objAdostream.SetEOS
  33.         set objAdostream=nothing
  34.         saveimg=savepath
  35.     end if
  36.     set xmlhttp=nothing
  37.     end function
  38. %>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值