Ver Mensaje Individual
  #4 (permalink)  
Antiguo 16/06/2014, 08:33
Avatar de Italico76
Italico76
 
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años, 1 mes
Puntos: 292
Respuesta: Redimensionar imagen para subir

Lo primero....... revisa el formulario:

<form action="recibir.php" method="post" enctype="multipart/form-data">
<input type="file" name="portada"/><p/>
<button>Enviar</button>
</form>

El enctype es importante y al recibir... verifica todo este bien:

Código PHP:
Ver original
  1. <?php
  2. var_dump($_FILES);
  3.  
  4. $input_file  = $_FILES['portada']['tmp_name'];

Ahora veamos el archivo .php que procesa:

Código PHP:
Ver original
  1. <?php
  2.  
  3. $input_file  = $_FILES['portada']['tmp_name'];
  4. $output_file = 'test.jpg';
  5.  
  6. resize($input_file,640,480,$output_file);
  7.  
  8. function resize($input_file,$new_width,$new_height,$output_file)
  9. {
  10.     list($width, $height) = getimagesize($input_file);
  11.  
  12.     $image_p = imagecreatetruecolor($new_width, $new_height);
  13.     $image = imagecreatefromjpeg($input_file);
  14.     imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  15.     imagejpeg($image_p, $output_file, 100);
  16. }
  17. ?>
  18. <img src="<?= $output_file ?>" />
__________________
Salu2!

Última edición por Italico76; 16/06/2014 a las 08:43