Help with foreach error

0

I am developing a system that needs to raise 2 types of img a small and a large one for the database, but when I send up 3 img small and 3 img big test my foreach does not go up all I do not know what to do, but I do not know what to do with it.

Code:

require"conexao.php";

    if(isset($_POST['port'])){  
    //dados que serão incluidos
    $nome = $_POST['galeria'];


foreach($_FILES['imgp']['tmp_name'] as $key => $name_temp){
        $name = $_FILES['imgp']['name'] [$key];
        $tmpnm = $_FILES['imgp']['tmp_name'][$key];
        $type = $_FILES['imgp']['type'][$key];
        $size = $_FILES['imgp']['size'][$key];

        $dir = "../images/small/portfolio/".$name;
        $mover = move_uploaded_file($tmpnm , $dir);

        foreach($_FILES['imgb']['tmp_name'] as $k => $n){
                $nomev = $_FILES['imgb']['name'] [$k];
                $t = $_FILES['imgb'] ['tmp_name'] [$k];
                $tipo = $_FILES['imgb']['type'][$k];
                $tam = $_FILES['imgb']['size'][$k];


        $dire = "../images/big/portfolio/".$nomev;
        $move = move_uploaded_file($t , $dire);


    if($mover&&$move){
             $sql = mysqli_query($mysqli, "INSERT INTO portfolio(nome, img, type, size, img_big, tipo, tam) 
                values('$nome', '$name', '$type', '$size', '$nomev', '$tipo', '$tam')") or die (mysqli_error());
            if($sql){
                echo "foi";
            }
            else{
                echo "erro database";
            }
        }else{
            echo"<h1>Ocorreu um erro.</h1>";
        }
      }
   }
}
    
asked by anonymous 11.01.2016 / 22:22

1 answer

0

In this case a foreach of the large images inside the small images is being used, try to use a foreach only.

The example below may not work 100% because you think that large images have the same     

if(isset($_POST['port'])){
//dados que serão incluidos
    $nome = $_POST['galeria'];


    foreach($_FILES['imgp']['tmp_name'] as $key => $name_temp){
        $name = $_FILES['imgp']['name'] [$key];
        $tmpnm = $_FILES['imgp']['tmp_name'][$key];
        $type = $_FILES['imgp']['type'][$key];
        $size = $_FILES['imgp']['size'][$key];

        $dir = "../images/small/portfolio/".$name;
        $mover = move_uploaded_file($tmpnm , $dir);

        $nomev = $_FILES['imgb']['name'] [$key];
        $t = $_FILES['imgb'] ['tmp_name'] [$key];
        $tipo = $_FILES['imgb']['type'][$key];
        $tam = $_FILES['imgb']['size'][$key];


        $dire = "../images/big/portfolio/".$nomev;
        $move = move_uploaded_file($t , $dire);


        if($mover&&$move){
            $sql = mysqli_query($mysqli, "INSERT INTO portfolio(nome, img, type, size, img_big, tipo, tam)
values('$nome', '$name', '$type', '$size', '$nomev', '$tipo', '$tam')") or die (mysqli_error());
            if($sql){
                echo "foi";
            }
            else{
                echo "erro database";
            }
        }else{
            echo"<h1>Ocorreu um erro.</h1>";
        }
    }
}
    
12.01.2016 / 16:51