Ver Mensaje Individual
  #10 (permalink)  
Antiguo 03/09/2008, 10:08
FajitaMaster
 
Fecha de Ingreso: agosto-2008
Mensajes: 21
Antigüedad: 18 años, 1 mes
Puntos: 3
Respuesta: Guardar una imagen de una url

Hace tiempo escribi esta funcion que hacia lo que estas pidiendo:


Código PHP:
function save_img($image) {
    
    
$img_file = file_get_contents($image);

    
$image_path = parse_url($image);
    
$img_path_parts = pathinfo($image_path['path']);
    
    
$filename = $img_path_parts['filename']
    
$img_ext = $img_path_parts['extension'];

    
$path = "img/";
    
$filex = $path . $filename . "." .$img_ext;
    
$fh = fopen($filex, 'w');
    
fputs($fh, $img_file);
    
fclose($fh);
    return 
filesize($filex);
} 

Asegurate que el " $path = "img/"; " existe en el servidor y que se escribible por el process de httpd

Si quieres usarlo puedes llamarlo de esta forma


Código PHP:
save_img("http://www.prueba.com/imagen.jpg") 

Saludos