How to send mutiplas images with this code!

Asked

Viewed 53 times

-1

Just sending a picture!

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");

Trying

        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");
  • Upload and Imagedata classes are not native, so it is impossible answer your question, because we don’t even know if this is a framework or code and therefore we don’t know the basics to be able to provide any help.

  • you, should not have understood the information about ! Just sending an image! where is the Wally ?

  • Without knowing the code we have no way to say exactly what is the correct (or most appropriate) use for the upload, after all if it is a personal code of yours (I refer to the classes) only you would be able to say, If it is a popular Framework then only if you tell what it is and what its version is. PS: Just to warn you, I didn’t give the downvote.

  • everything works imagedata and Upload what happens that it is not sending multiple images and only one image is sent ! folder creation , picture uploading all ok! as it comes to only one class as in the link above it believe , that do not need

  • An array is coming in $_FILES["image"]?

  • No! There’s nothing enough.

Show 1 more comment

1 answer

1

Thank you all for your help !

at great cost I discovered the problem and am passing the solution to all Thank you !

Codigo Reformulado!

<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>

Send

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.