Ver Mensaje Individual
  #8 (permalink)  
Antiguo 15/11/2012, 17:28
ALOYA
 
Fecha de Ingreso: noviembre-2012
Mensajes: 2
Antigüedad: 11 años, 6 meses
Puntos: 0
Respuesta: Copiar al servidor imagen desde URL

Gracias a todos por responder.

despues de unas cuantas horas para poder en tenderlo lo consegui en tender.
Ya que en el ejemplo que me puso mogurbon faltaba la barras de escape.

Bueno dejo un ejemplo de lo que eh echo:

Un formulario para poner los valores de la URL de la imagen, nombre y el formato,
y un archivo upload que recoje los datos del fomulario.

Formulario:

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>Subir Imagen desde URL</title>
<
style type="text/css">
<!--
.
text {
    
font-family"Trebuchet MS"ArialHelveticasans-serif;
    
font-size14px;
    
line-heightnormal;
    
font-weightnormal;
    
color#333;
    
text-decorationnone;
}
.for {
    
height20px;
    
width100%;
}
.
formu {
    
padding10px;
    
border2px solid #30F;
    
width455px;
}
-->
</
style>
</
head>

<
body>
<
div class="formu">
  <
form id="form1" name="form1" method="post" action="upload.php">
    <
table border="0" align="center" cellpadding="0" cellspacing="0">
      <
tr>
        <
td width="140" align="left" valign="middle" class="text">Enlace:</td>
        <
td width="15">&nbsp;</td>
        <
td width="300"><input name="filename" type="text" class="for" placeholder="Url de la Imagen" autofocus /></td>
      </
tr>
      <
tr>
        <
td width="140">&nbsp;</td>
        <
td width="15">&nbsp;</td>
        <
td width="300">&nbsp;</td>
      </
tr>
      <
tr>
        <
td width="140" align="left" valign="middle" class="text">Nombre:</td>
        <
td width="15">&nbsp;</td>
        <
td width="300"><input name="name" type="text" class="for" placeholder="Nombre de la Imagen" /></td>
      </
tr>
      <
tr>
        <
td width="140">&nbsp;</td>
        <
td width="15">&nbsp;</td>
        <
td width="300">&nbsp;</td>
      </
tr>
      <
tr>
        <
td width="140" align="left" valign="middle" class="text">Formato:</td>
        <
td width="15">&nbsp;</td>
        <
td width="300"><select name="format" class="for" placeholder="Url de la Imagen">
          <
option value=".jpg">JPG</option>
          <
option value=".png" selected="selected">PNG</option>
          <
option value=".gif">GIF</option>
        </
select></td>
      </
tr>
      <
tr>
        <
td width="140">&nbsp;</td>
        <
td width="15">&nbsp;</td>
        <
td width="300">&nbsp;</td>
      </
tr>
      <
tr>
        <
td width="140">&nbsp;</td>
        <
td width="15">&nbsp;</td>
        <
td width="300" align="right" valign="middle"><input name="" type="submit" value="Enviar" /></td>
      </
tr>
    </
table>
  </
form>
</
div>
</
body>
</
html
upload:

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Subir Imagen desde URL</title>
<style type="text/css">
<!--
.noval, .imagen {
    font-family: "Trebuchet MS", Verdana, Geneva, sans-serif;
    font-size: 16px;
    font-style: normal;
    line-height: normal;
    font-weight: normal;
    color: #333;
    text-decoration: none;
    text-align: center;
    height: 80px;
    width: 100%;
    border: 1px solid #666;
    padding-top: 12px;
}
.volver {
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size: 16px;
    font-style: normal;
    font-weight: bold;
    color: #333;
    text-decoration: none;
    height: 30px;
    width: 100px;
    padding-top: 6px;
    padding-left: 40px;
    border: 1px solid #000;
}
-->
</style>
</head>

<body>
<?php
$filename 
$_POST['filename']; //URL de la imagen a copiar
$name $_POST['name']; //Nombre final de la imagen
$format $_POST['format']; // Formato en el queremos guardar la imagen
if(preg_match("/.png/"$filename) || preg_match("/.jpg/"$filename) || preg_match("/.gif/"$filename) || preg_match("/.JPG/"$filename) || preg_match("/.GIF/"$filename)) {
$imagen file_get_contents($filename); // guardamos la imagen en la variable
file_put_contents('img/'.$name.$format,$imagen);// guardamos la imagen con nombre: imagen_copiada.jpg

echo '<div class="imagen"><img src="img/'.$name.$format.'" width="64" height="64" /></div>';
} else {
    echo 
'<div class="noval">Tipo de Imagen no Valido</div>';
    }
//
?>
<br />
<br />
<a href="index.php"><div class="volver">Volver</div></a>
</body>
</html>
Mas hay que crear una carpeta con el nombre img

Gracias por la ayuda.