Ver Mensaje Individual
  #6 (permalink)  
Antiguo 20/07/2021, 14:17
Avatar de fedefrankk
fedefrankk
 
Fecha de Ingreso: agosto-2007
Mensajes: 871
Antigüedad: 16 años, 8 meses
Puntos: 7
Pregunta Respuesta: Guardar dos imagenes desde un array

Hola Alexis88, te pego el código, algo estoy haciendo mal,

el php quedo asi:

Código PHP:
Ver original
  1. include("../config.php");
  2. $cone=conectar();
  3. $email=$_SESSION['email'];//rebe
  4.  
  5.  
  6. $names = [];
  7. $count = 0;
  8.  
  9. foreach ($_FILES as $file){
  10.     if ($file['error'] == UPLOAD_ERR_OK){
  11.         $name = $file['name'];
  12.         $temp = $file['tmp_name'];
  13.         $type = $file['type'];
  14.         $size = $file['size'];
  15.  
  16.         $names[$count] = $name;
  17.         $count++; //Se incrementa en uno cuando el archivo fue subido con éxito
  18.  
  19.         //Otras instrucciones...
  20.  
  21.         move_uploaded_file($temp, 'images/' . $name);
  22.  
  23.         if ($count == 2) break; //Se termina el bucle cuando se hayan subido dos archivos
  24.      
  25.     }
  26. }
  27.  
  28.  
  29. $query = "UPDATE alumnos SET img_a = '{$names[0]}', img_b = {$names[1]}' WHERE ClEmail = '$email'"; // LINEA 31
  30. $res = mysqli_query($cone, $query); // LINEA  32
  31.  
  32.  
  33. ?>

si hago esto

Código PHP:
Ver original
  1. print_r($names);

me da el siguiente error:

Array ( )
Notice: Undefined offset: 0 in C:\xampp\htdocs\03_V.01_2021_ESTEEEE\userspublicar \CuaSaveD.php on line 31

Notice: Undefined offset: 1 in C:\xampp\htdocs\03_V.01_2021_ESTEEEE\userspublicar \CuaSaveD.php on line 31

mi formulario es así:
Código HTML:
Ver original
  1. <div class="mb-3 fondo">
  2.   <label for="exampleFormControlInput1" class="form-label"><b>Elija una Imagen (2)</b></label>
  3.   <input type="file" class="form-control" name="file[]" multiple  >
  4. </div>

No se que estoy fallando ....
Gracias por tu paciencia.