Create thumbnail from multiple upload

1

Good afternoon, I already researched and tried several options and I could not.

I'm trying to upload multiple images, and each image generates a thumbnail and only records the original images in the database. But it generates the thumb of only one image or creates an image with all the names of the files of the upload, this happens when I change $novaImagem to $img for example:

tbn_1231455.jpg,tbn_3244545.jpg,tbn_8748545.jpg

I need help, follow my code below.

if (isset($_FILES['imagemlocal']))
{       
   $largura = 1024;
   $altura = 1024;
   $tamanho =  200000;
   $tmp = $_FILES['imagemlocal'];
   list($largura,$altura,$tip)=getimagesize($tmp);
   $dimensoes = getimagesize($imagemlocal["tmp_name"]);

   $img = array();
   for ($key = 0; $key < count($tmp['name']); $key++) {
      $path = $_FILES['imagemlocal']['name'][$key];
      $ext = pathinfo($path, PATHINFO_EXTENSION);
      $temp_name = $_FILES['imagemlocal']['tmp_name'][$key];
      $novaImagem = md5(uniqid(time())) . "." . $ext;
      $caminho = 'img/'.$novaImagem;
      move_uploaded_file($temp_name, $caminho);
      $img[] = ("$novaImagem");
   }
   $img = implode(', ', $img);          
}

//thumb

if($tip > 1) {
   $percent = 0.15;
   $new_largura = $largura * $percent;
   $new_altura = $altura * $percent;

   $thundebal = imagecreatefromjpeg($caminho);
}
else {
   $thundebal = imagecreatefrompng($caminho);
}

$Thundeball = imagecreatetruecolor($new_largura, $new_altura);
imagecopyresampled($Thundeball, $thundebal, 0, 0, 0, 0, $new_largura, $new_altura, $largura, $altura);
if($tip > 1) {
    imagejpeg($Thundeball,"img/".'/tbn_'.$novaImagem);
}
else {
    imagepng($Thundeball,"img/".'/tbn_'.$novaImagem);
}
    
asked by anonymous 24.11.2015 / 19:07

0 answers