ASP如何保存远程图片
记得很多的编辑器、自动采集系统都一个自动保存远程图片的功能,大概原理就是利用xmlhttp对象获取图片,然后用流对象写入保存,参照网上的代码,自己写了一个,与流传的代码没什么区别!代码如下,就一个函数:
<%Function SaveRemoteFile(sSavePath,sRemoteFileUrl) On Error Resume Next SaveRemoteFile = False Dim oXML : Set oXML = Server.CreateObject("Microsoft.XMLHTTP") With oXML .Open "Get",sRemoteFileUrl,False,"","" .Send If .Status<>200 Then Exit Function RemoteDate = .ResponseBody End With Set oXML = Nothing Dim oStream : Set oStream = Server.CreateObject("Adodb.Stream") With oStream .Type = 1 .Open .Write RemoteDate .SaveToFile sSavePath,2 If Err.Number=0 Then SaveRemoteFile = True .Close() End With Set oStream = NothingEnd Function'调用方法如下
SaveAddr=Server.MapPath("demo.gif")SourceURL="http://www.zzzyk.com/UploadFiles/2011-12/20111239429009575.gif"Call SaveRemoteFile(SaveAddr,SourceURL)%>Tag