Foros del Web » Programando para Internet » PHP »

error al subir multiples imagenes

Estas en el tema de error al subir multiples imagenes en el foro de PHP en Foros del Web. hola. desarrolle un mantenimiento de galeria de productos. al ingresar los productos, subo tambien las fotos a redimensionar. el proceso es que al subir las ...
  #1 (permalink)  
Antiguo 28/02/2012, 11:36
(Desactivado)
 
Fecha de Ingreso: abril-2008
Mensajes: 787
Antigüedad: 16 años
Puntos: 7
Pregunta error al subir multiples imagenes

hola. desarrolle un mantenimiento de galeria de productos. al ingresar los productos, subo tambien las fotos a redimensionar. el proceso es que al subir las fotos haga 2 redimensiones. una para el producto principal y las demás fotos para las galerías. al realizar el proceso me muestra el siguiente error:

Warning: getimagesize(C:\Windows\Temp\php7FC8.tmp) [function.getimagesize]: failed to open stream: No such file or directory in D:\AppServ\www\comenzando-desde-cero\repaso 9 (upload class)\ejemplo8 (cms galerias)\includes\class.upload.php on line 2877

Warning: fopen(C:\Windows\Temp\php7FC8.tmp) [function.fopen]: failed to open stream: No such file or directory in D:\AppServ\www\comenzando-desde-cero\repaso 9 (upload class)\ejemplo8 (cms galerias)\includes\class.upload.php on line 2936

Warning: move_uploaded_file(C:\Windows\Temp\php7FC8.tmp) [function.move-uploaded-file]: failed to open stream: No such file or directory in D:\AppServ\www\comenzando-desde-cero\repaso 9 (upload class)\ejemplo8 (cms galerias)\includes\class.upload.php on line 3635

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Windows\Temp\php7FC8.tmp' to 'productos/thumbnail/\22ada5ec9f4d73ea1e4d313f9c774284.jpg' in D:\AppServ\www\comenzando-desde-cero\repaso 9 (upload class)\ejemplo8 (cms galerias)\includes\class.upload.php on line 3635


aqui dejo mi codigo.

Código PHP:
Ver original
  1. if(isset($_FILES))
  2. {
  3.     $idproducto = mysql_insert_id();
  4.    
  5.     foreach($_FILES as $files => $file)
  6.     {
  7.         if(isset($file['name']) && !$file['error'] && $file['size']!=0)
  8.         {
  9.            
  10.             $f=1;
  11.             while($f)
  12.             {
  13.                 $nombre = 'productos/'.$f.$file['name'];
  14.                 $nombre_imagen = $f.$file['name'];
  15.                 clearstatcache();
  16.                
  17.                 if (file_exists($nombre))
  18.                     $f++;
  19.                 else
  20.                     $f=0;
  21.             }
  22.                
  23.                 // we instanciate the class for each element of $file
  24.                 $handle = new Upload($file);
  25.                
  26.                 // then we check if the file has been uploaded properly
  27.                 // in its *temporary* location in the server (often, it is /tmp)
  28.                 if ($handle->uploaded)
  29.                 {
  30.                     $handle->image_resize            = true;
  31.                     $handle->image_ratio_y           = true;
  32.                     $handle->image_x                 = 252;
  33.                     $handle->Process('productos/thumbnail/');
  34.                    
  35.                     // creo una variable $nombre_imagen para enviar los nombres de las imagenes.
  36.                     $nombre_imagen = $handle->file_dst_name;
  37.                     $handle->clean();                          
  38.                 }
  39.                 else
  40.                 {
  41.                     // if we're here, the upload file failed for some reasons
  42.                     // i.e. the server didn't receive the file
  43.                     echo '  file not uploaded on the server';
  44.                     echo '  Error: ' . $handle->error . '';
  45.                 }
  46.                
  47.                 // (imagen thb para las galerias)
  48.                 // we instanciate the class for each element of $file
  49.                 $imagen_thb = new Upload($file);
  50.        
  51.                 // then we check if the file has been uploaded properly
  52.                 // in its *temporary* location in the server (often, it is /tmp)
  53.                 if ($imagen_thb->uploaded)
  54.                 {
  55.                     $imagen_thb->image_resize         = true;
  56.                     $imagen_thb->image_ratio_fill     = true;      
  57.                     $imagen_thb->image_x              = 74;
  58.                     $imagen_thb->image_y              = 74;            
  59.                     $imagen_thb->Process('productos/thumbnail/');                      
  60.                     $foto_imagen_thb = $imagen_thb->file_dst_name;
  61.                    
  62.                 }
  63.                
  64.                 // pregunto si la variable a ingresar esta o no vacia.
  65.                 if($nombre_imagen!="" && $foto_imagen_thb!="")
  66.                 {
  67.                     // hacemos el insert para la tabla puente que en este caso es galeria_producto
  68.                     $sql_galeria_fotos  = "INSERT INTO galeria_producto(idproducto,imagen,imagen_thb)VALUES('$idproducto','$nombre_imagen','$foto_imagen_thb')";
  69.                     echo $sql_galeria_fotos;
  70.                     echo "<br />";
  71.                     query($sql_galeria_fotos,$cn) or die(mysql_error());               
  72.            
  73.                    
  74.                 }
  75.                                            
  76.                
  77.  
  78.         }
  79.        
  80.     } // termina el bucle foreach.
  81.    
  82.    
  83. }

saludos.
  #2 (permalink)  
Antiguo 29/02/2012, 02:10
Avatar de repara2  
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: error al subir multiples imagenes

El error lo da la classe que hace el upload porque los nombres de archivo que estás pasando no existen. También puede ser que no tengas permisos de escritura sobre el directorio. Comprueba que las rutas y nombres de archivos que pasas son correctos. Saludos
__________________
Fere libenter homines, id quod volunt, credunt.
  #3 (permalink)  
Antiguo 29/02/2012, 09:55
(Desactivado)
 
Fecha de Ingreso: abril-2008
Mensajes: 787
Antigüedad: 16 años
Puntos: 7
Respuesta: error al subir multiples imagenes

gracias por tu respuesta repara2. las rutas para almacenar las imagenes estan bien.

la carpeta "productos/" guardo las imagenes de tamaño 252 x 252 y para la galeria las guardo en la carpeta "productos/thumbnail/" de tamaño 72 x 72.

lo estoy probando localmente y me da el mismo problema.

saludos.

Código PHP:
Ver original
  1. if(isset($_FILES))
  2. {
  3.     $idproducto = mysql_insert_id();
  4.    
  5.     foreach($_FILES as $files => $file)
  6.     {
  7.         if(isset($file['name']) && !$file['error'] && $file['size']!=0)
  8.         {
  9.            
  10.             $f=1;
  11.             while($f)
  12.             {
  13.                 $nombre = 'productos/'.$f.$file['name'];
  14.                 $nombre_imagen = $f.$file['name'];
  15.                 clearstatcache();
  16.                
  17.                 if (file_exists($nombre))
  18.                     $f++;
  19.                 else
  20.                     $f=0;
  21.             }
  22.                
  23.                 // we instanciate the class for each element of $file
  24.                 $handle = new Upload($file);
  25.                
  26.                 // then we check if the file has been uploaded properly
  27.                 // in its *temporary* location in the server (often, it is /tmp)
  28.                 if ($handle->uploaded)
  29.                 {
  30.                     $handle->image_resize            = true;
  31.                     $handle->image_ratio_y           = true;
  32.                     $handle->image_x                 = 252;
  33.                     $handle->Process('productos/');
  34.                    
  35.                     // creo una variable $nombre_imagen para enviar los nombres de las imagenes.
  36.                     $nombre_imagen = $handle->file_dst_name;
  37.                     $handle->clean();                          
  38.                 }
  39.                 else
  40.                 {
  41.                     // if we're here, the upload file failed for some reasons
  42.                     // i.e. the server didn't receive the file
  43.                     echo '  file not uploaded on the server';
  44.                     echo '  Error: ' . $handle->error . '';
  45.                 }
  46.                
  47.                 // (imagen thb para las galerias)
  48.                 $imagen_thb = new Upload($file);
  49.        
  50.                 // then we check if the file has been uploaded properly
  51.                 // in its *temporary* location in the server (often, it is /tmp)
  52.                 if ($imagen_thb->uploaded)
  53.                 {
  54.                     $imagen_thb->image_resize         = true;
  55.                     $imagen_thb->image_ratio_fill     = true;      
  56.                     $imagen_thb->image_x              = 74;
  57.                     $imagen_thb->image_y              = 74;            
  58.                     $imagen_thb->Process('productos/thumbnail/');                      
  59.                     $foto_imagen_thb = $imagen_thb->file_dst_name;
  60.                    
  61.                 }
  62.                
  63.                 // pregunto si la variable a ingresar esta o no vacia.
  64.                 if($nombre_imagen!="" && $foto_imagen_thb!="")
  65.                 {
  66.                     // hacemos el insert para la tabla puente que en este caso es galeria_producto
  67.                     $sql_galeria_fotos  = "INSERT INTO galeria_producto(idproducto,imagen,imagen_thb)VALUES('$idproducto','$nombre_imagen','$foto_imagen_thb')";
  68.                     echo $sql_galeria_fotos;
  69.                     echo "<br />";
  70.                     query($sql_galeria_fotos,$cn) or die(mysql_error());               
  71.                    
  72.                     if($_POST['pagina']!="")
  73.                     {
  74.                         $pagina = $_POST['pagina'];
  75.                         $a = "&pagina=$pagina";
  76.                     }          
  77.                    
  78.                 }
  79.                    
  80.                     //header("Location:index.php?ok=1$a");                     
  81.                
  82.  
  83.         }
  84.        
  85.     } // termina el bucle foreach.
  86.    
  87.    
  88. }

Última edición por esaenz22; 29/02/2012 a las 10:12 Razón: correccion del post.
  #4 (permalink)  
Antiguo 29/02/2012, 11:28
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Respuesta: error al subir multiples imagenes

Puede que tu clase Upload haga uso de move_uploaded_file por lo que la segunda vez que lo usas ya no existan las imágenes temporales, y por eso te da error.

Saludos.

Etiquetas: imagenes, multiples, mysql, sql, tabla, variables
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:34.