ASP下载远程图片到本地的实现代码asp

/ / 2025-05-03   阅读:2559
ASP下载远程图片到本地的实现代码...

实际项目开发的过程中,客户有时候输入的图片URL是远程绝对网址,我们需要把远程图片下载到本地,主要使用Microsoft.XMLHTTP和Adodb.Stream远程获取图片,保存到本地。


ASP下载远程图片到本地的实现代码:

<%
sub downFile(url,filePath)
'远程获取文件 www.qdxw.net
'------------------------------------------------------
dim xmlhttp
set xmlhttp = server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "get",url,false
xmlhttp.send
dim html
html = xmlhttp.ResponseBody

'获取文件名
'-----------------------------------------------------
dim fileName,fileNameSplit
fileNameSplit = Split(url,"/")
fileName = fileNameSplit(Ubound(fileNameSplit))

'开始保存文件到本地
'-----------------------------------------------------
Set saveFile = Server.CreateObject("Adodb.Stream")
saveFile.Type = 1
saveFile.Open
saveFile.Write html
saveFile.SaveToFile filePath&"\"&fileName, 2
end sub

'测试下载
downFile "http://www.qdxw.net/images/logo2.gif",server.MapPath("/")
%>


我要评论

昵称:
验证码:

最新评论

共0条 共0页 10条/页 首页 上一页 下一页 尾页
意见反馈