您的位置:首页 > 编程语言 > ASP

ASP保存远程图片文件到本地代码

2008-11-22 18:22 691 查看
<IFRAME name=google_ads_frame marginWidth=0 marginHeight=0 src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-4490194096475053&dt=1227349296343&lmt=1226285505&prev_slotnames=1891601125&output=html&slotname=3685991503&correlator=1227349296312&url=http%3A%2F%2Fwww.corange.cn%2Farchives%2F2008%2F08%2F1565.html&ea=0&ref=http%3A%2F%2Fwww.corange.cn%2Fhtml%2Fcorange__90.html&frm=0&ga_vid=2091876339.1227189135&ga_sid=1227349233&ga_hid=96595439&ga_fc=true&flash=9.0.124.0&u_h=768&u_w=1024&u_ah=715&u_aw=1024&u_cd=32&u_tz=480&u_java=true&dtd=16" frameBorder=0 width=300 scrolling=no height=250 allowTransparency></IFRAME><%
Function SaveRemoteFile(LocalFileName,RemoteFileUrl)
SaveRemoteFile=True
dim Ads,Retrieval,GetRemoteData
Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", RemoteFileUrl, False, "", ""
.Send
If .Readystate<>4 then
SaveRemoteFile=False
Exit Function
End If
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
Set Ads = Server.CreateObject("Adodb.Stream")
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile server.MapPath(LocalFileName),2
.Cancel()
.Close()
End With
Set Ads=nothing
End Function
%>

<%
'以下为调用示例:
remoteurl="http://www.yiwu-jewelry.cn/images_yiwu/logo.jpg"'远程文件名(绝对全路径)
localfile="images/"&Replace(Replace(Replace(Now(),"-","")," ",""),":","")&Right(remoteurl,4)'本机文件名(可自定义)
If SaveRemoteFile(localfile,remoteurl)=True Then
Response.Write("成功保存:"&localfile)
End If
%>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  asp function