0
good people have a problem I have a form that uploads photos and saves the name in the database and moves the file to specified folder the problem this loop always repeats 5 times if I insert 5 photos everything happens normal photos are saved in the bank and moved for more folder if sending 1 photo of an error saying
Notice: Undefined offset: 2 in
More if sending 2 of an error
Notice: Undefined offset: 3 in
Plus if sending 3 of an error
Notice: Undefined offset: 4 in
More if sending 5 no error
plus photos are moved to folder and bank and saved name plus adds 5 lines for example if I send a photo only it is moved to folder more in bank and solvo 5 lines 4 are empty and one with the name of the photo I sent
<form action="recebe_form.php" method="post" enctype="multipart/form-data">
<label class="label">
<span class="legend">fotos adicionais</span>
<input type="file" name="fotos[]" multiple/>
</label>
</form>
<?php
include_once("/../../../_app/config.inc.php");
// Pasta de destino das fotos
$Destino = "../../../../img_uploads/windows/1/";
// Obtém dados do upload
$Fotos = $_FILES["fotos"];
// Contagem de fotos enviadas
$Conta = 0;
// Itera sobre as enviadas e processa as validações e upload
for($i = 0; $i < sizeof($Fotos); $i++)
{
// Passa valores da iteração atual
$Nome = $Fotos["name"][$i];
$Tamanho = $Fotos["size"][$i];
$Tipo = $Fotos["type"][$i];
$Tmpname = $Fotos["tmp_name"][$i];
// Verifica se tem arquivo enviado
if($Tamanho > 0 && strlen($Nome) > 1)
{
// Verifica se é uma imagem
if(preg_match("/^image\/(gif|jpeg|jpg|png)$/", $Tipo))
{
// Caminho completo de destino da foto
$Caminho = $Destino . $Nome;
// Tudo OK! Move o upload!
move_uploaded_file($Tmpname, $Caminho);
}
} $query = $pdo->query("INSERT INTO so_windows_gallery SET image ='$Nome', id_ = 1 ");
}
array (size=5)
'name' =>
array (size=1)
0 => string '17172939023126.jpg' (length=18)
'type' =>
array (size=1)
0 => string 'image/jpeg' (length=10)
'tmp_name' =>
array (size=1)
0 => string 'C:\wamp64\tmp\phpBA42.tmp' (length=25)
'error' =>
array (size=1)
0 => int 0
'size' =>
array (size=1)
0 => int 194677
Make the modification I mentioned in my reply and you will not need to stop the loop. Your code is simply counting the number of elements in the wrong array.
– KillerJack
I’ll try and get it fixed
– diogo Dsa