在动网看到有篇介绍保存远程图片的函数,感觉功能相当好,特经过我个人的修改,共享出来。
<%
'============================================
'函数作用:远程图片自动保存到本地服务器
'修改时间:2006-7-3 21:21
'传人参数:
' LocalFileName:本地文件名
' RemoteFileUrl:远程文件URL
'============================================
sub SaveRemoteFile(LocalFileName,RemoteFileUrl)
dim Ads,Retrieval,GetRemoteData
Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", RemoteFileUrl, False, "", ""
.Send
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
Set Ads = Server.CreateObject("Adodb.Stream")
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile LocalFileName,2
.Cancel()
.Close()
End With
Set Ads=nothing
end sub
RemoteFileUrl = "http://www.it365cn.com/bbs/images/mainlogo.gif" '获取远程图片
FileExt = right(RemoteFileUrl,4) '获取远程图片的格式
'随机文件名称
randomize
ranNum = int(9*10^3*rnd)+10^3
dtNow = Now()
FileName = year(dtNow) & right("0" & month(dtNow),2) & right("0" & day(dtNow),2) & right("0" & hour(dtNow),2) & right("0" & minute(dtNow),2) & right("0" & second(dtNow),2) & ranNum & FileExt
LocalFileName = "./" '保存本地路径
if right(LocalFileName,1) <> "/" then LocalFileName = LocalFileName & "/"
SaveFile = server.mappath(LocalFileName & FileName)
SaveRemoteFile SaveFile,RemoteFileUrl '保存远程图片
response.write "保存成功,<a href=""" & LocalFileName & FileName & """ target=""_blank"">点击查看图片文件....</a>"
%>