把文章內(nèi)容中涉及到的圖片自動(dòng)保存到本地服務(wù)器
發(fā)表時(shí)間:2024-01-16 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]<%const savepath="tempfile/"function myreplace(str)newstr=strset objregEx = new RegExpobjregEx.IgnoreCase = trueobjregEx.Global = trueob...
<%
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
%>