How to send multiple images with this code! [closed]

-1

You are just sending an image!

My Form

<form role="form" method="post" action="./?action=addmult" enctype="multipart/form-data">
         <div class="form-group">
           <label>Imagen (480x480)</label>
           <input type="file" name="image" multiple="">
         </div>
         <div class="form-group">
           <label>Pasta</label>
           <input type="text" name="folder" class="form-control" placeholder="Pasta">
          </div>
           <button type="submit" class="btn btn-primary">Enviar</button>

I'm using the Class Upload !

My code.

if(isset($_FILES["image"])){
    $image=new Upload($_FILES["image"]);
    if($image->uploaded){
        $folder = 'teste';
        $new = mkdir($target_dir . $folder . "/");
        $image->Process("storage/images/".$folder);
        if($image->processed){
            $img = new ImageData();
            $p->title = $_POST["title"];
            $p->content = $_POST["content"];
            $img->src = $image->file_dst_name;
            $img->user_id=$_SESSION["user_id"];
            $imgx=$img->add();
        }
    }
}
Core::redir("./?view=galery");

Attempt

        if(isset($_FILES["image"])){

    $handle=new Upload($_FILES["image"]);
    $files = array();
    foreach ($_FILES['image'] as $k => $l) {
    foreach ($l as $i => $v) {
    if (!array_key_exists($i, $files))
    $files[$i] = array();
    $files[$i][$k] = $v;
    }
    }
    foreach ($files as $file) {
    $handle = new Upload($file);
    if($handle->uploaded){

    $folder = $_POST["folder"];
    $new = mkdir($target_dir . $folder . "/");
    $handle->Process("storage/images/".$folder);

    if($handle->processed){

        $img = new ImageData();
        $p->title = $_POST["title"];
        $p->content = $_POST["content"];
        $img->src = $image->file_dst_name;
        $img->user_id=$_SESSION["user_id"];
        $imgx=$img->add();
        echo 'OK';
        } else {
        echo 'Error: ' . $handle->error;
        }
        } else {
        echo 'Error: ' . $handle->error;
        }
        unset($handle);
      }

    Core::redir("./?view=galery");
    
asked by anonymous 04.12.2017 / 15:16

1 answer

1

Thank you all for the help!

At great cost I discovered the problem and I am passing the solution to everyone  Thanks!

Reformulated Code!

<form role="form" method="post" action="./?action=addmult" 
enctype="multipart/form-data">
 <label>Selecione as imagens</label>
 <div class="form-group">
                    <label>Pasta</label>
                <input type="text" name="folder" class="form-control" placeholder="Pasta">
            </div>
    <div class="file-loading">
        <input id="file-0c" class="file" type="file" name="image[]" multiple data-min-file-count="0">
    </div>

Submit

The solution found was only one [] in name="image" for name="image []"     

04.12.2017 / 23:01