How to upload multiple images to the server in a folder spesifica with PHP? [closed]

closed . This question is based on opinions . It does not currently support answers.

want to improve this question? update the question to that can be answered with data and citations at edit this post .

Closed 4 years ago .

Improve this question

I want from a form to be able to upload several images at the same time, to be sent by post, to upload.php this form and that in process.php be sent the form in such a way that you can store them in a folder thickens.

 0
Author: Stivents , 2016-11-01

1 answers

Here I leave an example to your answer.

Page subir.php

<form method="post" action="proceso.php" enctype="multipart/form-data">
    Subir imagen: <input type="file" name="file[]" multiple>
    <input type="submit" value="Subir imágenes" />
 </form>

Page proceso.php

<?php

if (isset($_FILES["file"]))
{
   $reporte = null;
     for($x=0; $x<count($_FILES["file"]["name"]); $x++)
    {
      $file = $_FILES["file"];
      $nombre = $file["name"][$x];
      $tipo = $file["type"][$x];
      $ruta_provisional = $file["tmp_name"][$x];
      $size = $file["size"][$x];
      $dimensiones = getimagesize($ruta_provisional);
      $width = $dimensiones[0];
      $height = $dimensiones[1];
      $carpeta = "tu_ruta/";

      if ($tipo != 'image/jpeg' && $tipo != 'image/jpg' && $tipo != 'image/png' && $tipo != 'image/gif')
      {
          $reporte .= "<p style='color: red'>Error $nombre, el archivo no es una imagen.</p>";
      }
      else if($size > 1024*1024)
      {
          $reporte .= "<p style='color: red'>Error $nombre, el tamaño máximo permitido es 1mb</p>";
      }
      else if($width > 500 || $height > 500)
      {
          $reporte .= "<p style='color: red'>Error $nombre, la anchura y la altura máxima permitida es de 500px</p>";
      }
      else if($width < 60 || $height < 60)
      {
          $reporte .= "<p style='color: red'>Error $nombre, la anchura y la altura mínima permitida es de 60px</p>";
      }
      else
      {
          $src = $carpeta.$nombre;

          //Caragamos imagenes al servidor
          move_uploaded_file($ruta_provisional, $src);       

          //Codigo para insertar imagenes a tu Base de datos.
          //Sentencia SQL

          echo "<p style='color: blue'>La imagen $nombre ha sido subida con éxito</p>";
      }
    }

    echo $reporte;
}
 5
Author: Diablo, 2016-11-01 20:09:36