- <%
- 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
- end if
- set xmlhttp=nothing
- end function
- %>
Asp把文章内容中涉及到的图片自动保存到本地服务器
最新推荐文章于 2026-01-01 21:40:23 发布
本文介绍了一个用于从文本中提取并替换图片链接的功能。通过正则表达式匹配到 HTTP 协议开头的 jpg、gif、png 或 bmp 图片链接,并将这些图片下载到本地指定文件夹。同时,该功能会用保存后的本地图片路径替换原文中的远程链接。
684

被折叠的 条评论
为什么被折叠?



