sql >> Database >  >> RDS >> Mysql

Meerdere afbeeldingen uploaden naar Mysql-database

U kunt ofwel 3 ingangen toevoegen

<td rowspan="1">
    <input type="file" id="upload" name="images1[]">
</td>
<td rowspan="1">
    <input type="file" id="upload" name="images1[]">
</td>
<td rowspan="1">
    <input type="file" id="upload" name="images1[]">
</td>

Of laat uw ene invoer multiple toestaan ingangen

<td rowspan="1">
    <input type="file" id="upload" multiple name="images1[]">
</td>

Hoe dan ook, je krijgt dan een $_FILES['images1'] dat is nu een array

Dan hoeft je PHP-code alleen maar over de $_FILES-array te lopen

<?php
    include("koneksi.php");
    if(isset($_POST['Input'])) {
        $Kode = $_POST['Kode'];
        $Tipe = $_POST['Tipe'];

        // you should really be checking for upload errors
        foreach ($_FILES['images1']['error'] as $err) {
           switch ($err) {
              case UPLOAD_ERR_NO_FILE:
                  echo 'No file sent.';
                  exit;
              case UPLOAD_ERR_INI_SIZE:
              case UPLOAD_ERR_FORM_SIZE:
                  echo 'Exceeded filesize limit.';
                  exit;
            }
        }

        for($x=0; $x<count($_FILES['images1']['tmp_name']); $x++ ) {

            $file_name = $_FILES['images1']['name'][$x];
            $file_size = $_FILES['images1']['size'][$x];
            $file_tmp  = $_FILES['images1']['tmp_name'][$x];

            $t = explode(".", $file_name);
            $t1 = end($t);
            $file_ext = strtolower(end($t));

            $ext_boleh = array("jpg", "jpeg", "png", "gif", "bmp");

            if(in_array($file_ext, $ext_boleh)) {
                $sumber = $file_tmp;
                $tujuan = "images/" . $file_name;
                move_uploaded_file($sumber, $tujuan);

                $sql = "insert into database_latihan values ('$Kode' , '$Tipe' , '$tujuan')";
               mysqli_query($koneksi, $sql);
            }else  {
                echo "Only Images can be store!";
            }
        } // endfor
    }
?>


  1. Ondersteunt Postgres geneste of autonome transacties?

  2. SQLite DATEADD() Equivalent

  3. Hoe gebruik ik de opbouwfunctie voor expressies in Access 2016?

  4. Hoe dilemma te benaderen:exportorders van oud magento-systeem importeren in nieuw magento, overlappende ID's