Scroll through the values of an input file in PHP?

Asked

Viewed 42 times

0

I’m trying to go through an array of various images in PHP, however, I’m not getting it, follow the code below:

HTML:

 <input type="file" name="img[]" onchange="this.parentNode.setAttribute('title', this.value.replace(/^.*[\\/]/,''))" />
 <input type="file" name="img[]" onchange="this.parentNode.setAttribute('title', this.value.replace(/^.*[\\/]/,''))" />
 <input type="file" name="img[]" onchange="this.parentNode.setAttribute('title', this.value.replace(/^.*[\\/]/,''))" />

PHP:

    $tipos_img = array(
    "image/jpg",
    "image/png",
    "image/jpeg"
   );
   $verifica_quant_img = 0;
   $caminho_fixo = "itens_fixos/imgjogos/";
 foreach ($_FILES['img'] as $img){    
    if (!empty($img['name'])){
          $verifica_quant_img = $verifica_quant_img + 1;
        $caminho = "itens_fixos/imgjogos/".$img['name'];
    if (!in_array($tipos_img, $img['type'])){
     echo "<script language='javascript' type='text/javascript'>alert('Os formatos de imagens aceitos são, 'JPG','PNG' e 'JPEG'.');window.location.href='indexjogo.php';</script>";
        exit;
    }
    if ($img['size'] > 3145728){
        echo "<script language='javascript' type='text/javascript'>alert('Tamanho máximo das imagens é de 3MBs.');window.location.href='indexjogo.php';</script>";
        exit;
    }
    if (file_exists($caminho)){
            echo "<script language='javascript' type='text/javascript'>alert('A imagem"+$img['name']+" já existe.');window.location.href='indexjogo.php';</script>";
        exit;
    }
    }
}

HERE IS THE MISTAKE: inserir a descrição da imagem aqui

  • What would be the problem?

  • This one below the code.

  • rsrs truth.. had not noticed. Thanks!

  • 1

    Take a look https://jsfiddle.net/3bhjfg9y/1/

No answers

Browser other questions tagged

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