Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/02/2012, 09:41
Avatar de kimmy
kimmy
 
Fecha de Ingreso: julio-2008
Mensajes: 841
Antigüedad: 15 años, 9 meses
Puntos: 15
Error cuando trato de subir varias fotos y alguna esta vacia

Hola amigos. Tengo un formulario para subir varias fotos y al guardar le hace resize y crea una miniatura. Además, se le asigna un nombre que consiste en el nombre de la foto, un numero y una extension jpg. Esto me funciona perfectamente cuando cargo todas las fotos pero si faltan fotos me da error.

La cuestión es que no se como decirle que si una foto no existe no hacer el proceso.

Este es mi formulario:

Código HTML:
Ver original
  1. <form action="fotos_cargadas.php" name="form2" enctype="multipart/form-data" id="form2" method="post" >
  2.         <tr>
  3.         <td>Id de Posada</td>
  4.         <td><input name="id_posada" type="text" value="<?php echo $id_posada; ?>" /></td>
  5.         </tr>
  6.         <tr>
  7.         <td>Código Posada</td>
  8.         <td><input name="codigo" type="text" value="<?php echo $codigo; ?>" /></td>
  9.         </tr>
  10.         <tr>
  11.         <td>Nombre Posada</td>
  12.         <td><input name="nombre_posada" type="text" value="<?php echo $nombre_posada; ?>" /></td>
  13.         </tr>
  14.         <tr>
  15.             <td>FOTO 1</td>
  16.             <td>
  17.               <input type="file" name="foto1" id="foto1" />
  18.             </td>
  19.         </tr>    
  20.         <tr>
  21.             <td>FOTO 2</td>
  22.             <td>
  23.               <input type="file" name="foto2" id="foto2" />
  24.             </td>
  25.         </tr>    
  26.         <tr>
  27.             <td>FOTO 3</td>
  28.             <td>
  29.               <input type="file" name="foto3" id="foto3" />
  30.             </td>
  31.         </tr>    
  32.         <tr>
  33.             <td>FOTO 4</td>
  34.             <td>
  35.               <input type="file" name="foto4" id="foto4" />
  36.             </td>
  37.         </tr>    
  38.         <tr>
  39.             <td>FOTO 5</td>
  40.             <td>
  41.               <input type="file" name="foto5" id="foto5" />
  42.             </td>
  43.         </tr>    
  44.         <tr>
  45.             <td>FOTO 6</td>
  46.             <td>
  47.               <input type="file" name="foto6" id="foto6" />
  48.             </td>
  49.         </tr>    
  50.         <tr>
  51.             <td>FOTO 7</td>
  52.             <td>
  53.               <input type="file" name="foto7" id="foto7" />
  54.             </td>
  55.         </tr>    
  56.         <tr>
  57.             <td>FOTO 8</td>
  58.             <td>
  59.               <input type="file" name="foto8" id="foto8" />
  60.             </td>
  61.         <tr>
  62.           <td colspan="2" align="center"><input name="cargar" type="submit" id="cargar" value="Cargar" /></td>
  63.         </tr>
  64.         </tr>  
  65.      </form>

y aqui las recibo:

Código PHP:
Ver original
  1. require_once '../../func/ResizePicture.php';
  2. $foto_nombre = $_POST['codigo'];
  3. $numero1 = '1';
  4. $numero2 = '2';
  5. $numero3 = '3';
  6. $numero4 = '4';
  7. $numero5 = '5';
  8. $numero6 = '6';
  9. $numero7 = '7';
  10. $numero8 = '8';
  11.  
  12. $ruta1 = "../../images/galeria/large/";
  13. $ruta2 = "../../images/galeria/thumbnails/";
  14.  
  15. $extension = "jpg";
  16.  
  17. $image = new ResizePicture($_FILES['foto1']['tmp_name']);
  18.  
  19.         $image->resize(444,420);
  20.     $w444 = $foto_nombre. '_' .$numero1. '.' . $extension;
  21.         $image->save($ruta1.$w444);
  22.  
  23.         $image->resize(54,54);
  24.         $w54 = $foto_nombre. '_' .$numero1. '.' . $extension;
  25.         $image->save($ruta2.$w54);
  26.  
  27. $image = new ResizePicture($_FILES['foto2']['tmp_name']);
  28.  
  29.         $image->resize(444,420);
  30.         $w444 = $foto_nombre. '_' .$numero2. '.' . $extension;
  31.         $image->save($ruta1.$w444);
  32.  
  33.         $image->resize(54,54);
  34.     $w54 = $foto_nombre. '_' .$numero2. '.' . $extension;
  35.         $image->save($ruta2.$w54);
  36.  
  37.  
  38. $image = new ResizePicture($_FILES['foto3']['tmp_name']);
  39.  
  40.         $image->resize(444,420);
  41.     $w444 = $foto_nombre. '_' .$numero3. '.' . $extension;
  42.         $image->save($ruta1.$w444);
  43.  
  44.         $image->resize(54,54);
  45.     $w54 = $foto_nombre. '_' .$numero3. '.' . $extension;
  46.         $image->save($ruta2.$w54);
  47.  
  48. $image = new ResizePicture($_FILES['foto4']['tmp_name']);
  49.  
  50.         $image->resize(444,420);
  51.         $w444 = $foto_nombre. '_' .$numero4. '.' . $extension;
  52.         $image->save($ruta1.$w444);
  53.  
  54.         $image->resize(54,54);
  55.     $w54 = $foto_nombre. '_' .$numero4. '.' . $extension;
  56.         $image->save($ruta2.$w54);
  57.  
  58. $image = new ResizePicture($_FILES['foto5']['tmp_name']);
  59.  
  60.         $image->resize(444,420);
  61.     $w444 = $foto_nombre. '_' .$numero5. '.' . $extension;
  62.         $image->save($ruta1.$w444);
  63.  
  64.         $image->resize(54,54);
  65.     $w54 = $foto_nombre. '_' .$numero5. '.' . $extension;
  66.         $image->save($ruta2.$w54);
  67.  
  68. $image = new ResizePicture($_FILES['foto6']['tmp_name']);
  69.  
  70.         $image->resize(444,420);
  71.     $w444 = $foto_nombre. '_' .$numero6. '.' . $extension;
  72.         $image->save($ruta1.$w444);
  73.  
  74.          $image->resize(54,54);
  75.     $w54 = $foto_nombre. '_' .$numero6. '.' . $extension;
  76.         $image->save($ruta2.$w54);
  77.  
  78. $image = new ResizePicture($_FILES['foto7']['tmp_name']);
  79.  
  80.         $image->resize(444,420);
  81.     $w444 = $foto_nombre. '_' .$numero7. '.' . $extension;
  82.         $image->save($ruta1.$w444);
  83.  
  84.         $image->resize(54,54);
  85.     $w54 = $foto_nombre. '_' .$numero7. '.' . $extension;
  86.         $image->save($ruta2.$w54);
  87.  
  88. $image = new ResizePicture($_FILES['foto8']['tmp_name']);
  89.  
  90.         $image->resize(444,420);
  91.     $w444 = $foto_nombre. '_' .$numero8. '.' . $extension;
  92.         $image->save($ruta1.$w444);
  93.  
  94.         $image->resize(54,54);
  95.     $w54 = $foto_nombre. '_' .$numero8. '.' . $extension;
  96.         $image->save($ruta2.$w54);

Por favor orientenme un poco.... Gracias
__________________
Caminando con el corazón partío