Ver Mensaje Individual
  #92 (permalink)  
Antiguo 30/01/2006, 13:47
tammander
 
Fecha de Ingreso: enero-2006
Ubicación: Torroles (Costa der Só)
Mensajes: 1.017
Antigüedad: 18 años, 3 meses
Puntos: 7
Copiar una imagen desde una dirección web externa

Copia desde una dirección web cualquiera una imagen a nuestro servidor y luego nos devuelve el path de la imagen.

Código:
<%@ Language=VBScript %>
<% Option Explicit

'***********************************************
'* Copia una Imagen desde una direccion, 
'* la graba en un directorio de nuestro equipo
'* y devuelve su direccion
'***********************************************

Function CopiaImagenDesde(URL)
On Error Resume Next
Err.Clear
'*
'* Toma la imagen
'*
Dim objXML
'Set objXML = Server.CreateObject("Msxml2.ServerXMLHTTP")
Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
objXML.Open "GET",URL,False
objXML.Send
Dim binXML
binXML = objXML.ResponseBody
If Err.Number <> 0 Or objXML.Status <> 200 Then
	CopiaImagenDesde = False
	Exit Function
End If
Set objXML = Nothing
'*
'* Graba Imagen en images\ o en donde se quiera
'*
Dim strIMG
strIMG = "images\" & Mid(URL,InStrRev(URL,"/")+1)
Dim objADO
Set objADO = CreateObject("ADODB.Stream")
objADO.Type = 1
objADO.Open
objADO.Write binXML
objADO.SaveToFile Server.MapPath(strIMG),2
Set objADO = Nothing

CopiaImagenDesde = strIMG
End Function
%>
Y esta es su forma de utilizarlo

Código:
<html>
<body>
<img src="<%=CopiaImagenDesde("http://www.undominio.com/dir/imageness/archivo.gif")%>"
border="0" alt="">
</body>
</html>
Un saludo