ASP儲存遠端圖片檔案到原生程式碼

piperzero發表於2008-11-22
<IFRAME name=google_ads_frame marginWidth=0 marginHeight=0 src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-4490194096475053&amp;dt=1227349296343&amp;lmt=1226285505&amp;prev_slotnames=1891601125&amp;output=html&amp;slotname=3685991503&amp;correlator=1227349296312&amp;url=http%3A%2F%2Fwww.corange.cn%2Farchives%2F2008%2F08%2F1565.html&amp;ea=0&amp;ref=http%3A%2F%2Fwww.corange.cn%2Fhtml%2Fcorange__90.html&amp;frm=0&amp;ga_vid=2091876339.1227189135&amp;ga_sid=1227349233&amp;ga_hid=96595439&amp;ga_fc=true&amp;flash=9.0.124.0&amp;u_h=768&amp;u_w=1024&amp;u_ah=715&amp;u_aw=1024&amp;u_cd=32&amp;u_tz=480&amp;u_java=true&amp;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
%>

相關文章