实际项目开发的过程中,客户有时候输入的图片URL是远程绝对网址,我们需要把远程图片下载到本地,主要使用Microsoft.XMLHTTP和Adodb.Stream远程获取图片,保存到本地。
<% 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("/") %>