您现在的位置:首页 >> 分类信息 >> 其他信息 >> 内容

asp获取内容中远程图片保存到本地

时间:2025/9/13 20:44:23 点击:

  核心提示:%const con='img src=http://www.xtxdl.com/xiaohua/images/logo.gif'brbrstrong123笑话大全,专业建站,高质低价!QQ:1016...

<%

const con="<img src=http://www.xtxdl.com/xiaohua/images/logo.gif'><br><br><strong>123笑话大全,专业建站,高质低价!QQ:1016964448.</p>"


const savepath="pic"

'判断文件夹是否存在,不存在自动创建
FilePath=Server.Mappath(savepath)
Set Fso = Server.CreateObject("Scripting.FileSystemObject")
If Not Fso.FolderExists(FilePath) Then Fso.CreateFolder (FilePath)
Set Fso = Nothing

 

 

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

 

response.Write  myreplace(con)
%>

作者:不详 来源:网络
共有评论 0 条相关评论
发表我的评论
  • 大名:
  • 内容:
  • 123笑话大全-短信大全-成人笑话-成人短信(www.ji-su.com.cn) © 2026 版权所有 All Rights Reserved.
  • www.ji-su.com.cn 冀ICP备05011918号
  • Powered by V3.0