Comunidad de diseño web y desarrollo en internet online

Copiar a mi servidor una imagen externa?

Citar            
MensajeEscrito el 12 Jun 2008 07:40 pm
Saludos,

busco un código PHP que permita copiar una imagen desde internet (un servidor externo) a mi servidor, es esto posible o estoy diciendo una barbaridad?

Es porque haciendo link desde flash a esa imagen externa solo se puede ver con firefox pero de internet explorer nada y me han recomendado que pase por php.

Muchas gracias!

nanel

Por nanel

6 de clabLevel



Genero:Masculino  

msie7
Citar            
MensajeEscrito el 12 Jun 2008 08:15 pm
No es ninguna bobada.

Necesitarás que tu server tenga "allow_url_fopen=on".
(puedes consultarlo con este comando de php:)

Código :

<?php
echo phpinfo();
?>

(y luego buscando (Ctrl+F), en el documento que devuelve, a ver si está "on", u "off")

Pero te digo:
En los servers "compartidos, de pago", suele estar "off" (cuestiones de seguridad), así que tendrás que pedirles a los admins que lo pongan ("on"), o intentarlo tú mismo, con alguna de estas líneas en el .htaccess:

Código :

php_flag allow_url_fopen on
php_value allow_url_fopen 1



Más documentación (le mejor):

Por El Oso Amoroso

Claber

1780 de clabLevel

6 tutoriales

 

Madrid, España, Europa, Eurasia, La Tierra, Sist.Solar, Vía Láctea, UNIVERSO

firefox
Citar            
MensajeEscrito el 12 Jun 2008 09:02 pm
si no, con las librerías curl (libcurl)

Por _CONEJO

BOFH

7639 de clabLevel

17 tutoriales
21 articulos

 

firefox
Citar            
MensajeEscrito el 12 Jun 2008 10:30 pm
Muchas gracias rizome!

buscando y con la ayuda de The Fricky,

lo he conseguido con esto:

<?php
// Set the path to the image to resize
$input_image = "http://static.die.net/moon/512.jpg";
// Get the size of the original image into an array
$size = getimagesize( $input_image );
// Set the new width of the image
$thumb_width = "512";
// Calculate the height of the new image to keep the aspect ratio
$thumb_height = "512";
// Create a new true color image in the memory
$thumbnail = ImageCreateTrueColor( $thumb_width, $thumb_height );
// Create a new image from file
$src_img = ImageCreateFromJPEG( $input_image );
// Create the resized image
ImageCopyResampled( $thumbnail, $src_img, 0, 0, 0, 0, $thumb_width, $thumb_height, $size[0], $size[1] );
// Save the image as resized.jpg
ImageJPEG( $thumbnail, "luna.jpg" );
// Clear the memory of the tempory image
ImageDestroy( $thumbnail );
?>

Ahora solo me falta establecer los permisos en la carpeta del servidor para que funcione porque en local me va de perlas!

Muy amable!

nanel

Por nanel

6 de clabLevel



Genero:Masculino  

msie7
Citar            
MensajeEscrito el 12 Jun 2008 10:31 pm
Disculpa _conejo que no te había visto!!

Muchas gracias a ti también!!

nanel

Por nanel

6 de clabLevel



Genero:Masculino  

msie7
Citar            
MensajeEscrito el 12 Jun 2008 10:37 pm
Creo que esto sería más correcto,... pero ni idea

Código :

         $ch = curl_init($archivo_en_OTRO_servidor);
         $fp = fopen($archivo_en_tu_servidor, "w");

         curl_setopt($ch, CURLOPT_FILE, $fp);
         curl_setopt($ch, CURLOPT_HEADER, 0);

         curl_exec($ch);
         curl_close($ch);
         fclose($fp);
         chmod($archivo_en_tu_servidor,0777);

Por _CONEJO

BOFH

7639 de clabLevel

17 tutoriales
21 articulos

 

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.