I am not able to register multiple comma-separated image names in a single-column column, I am able to do multiple uploads, but each image name is registered on a different row in the database. And it wanted to type like this: the user uploads 5 photos and all the images inserted in the same column of the same line, each separated by comma in the database:
--------------------------------------------------------------------------
ID | img
--------------------------------------------------------------------------
1 | image(1).jpg, image(2).jpg, image(3).jpg, image(4).jpg, image(5).jpg
--------------------------------------------------------------------------
Here is the Form:
<form action="public.php" method="post" enctype="multipart/form-data">
<input type="file" name="images[]" accept="image/png, image/jpg, image/jpeg" multiple />
<input type="submit" />
</form>
Following is the PHP code:
$fotoPost = $_FILES['images']; //recebe as imagens passadas pelo input file
$numFoto = count(array_filter($fotoPost['name'])); //conta quantas imagens foram inseridas no input
$folder = "../../arquivs/postagensImg/$dash/"; // pasta do arquivo
$extensao= array('image/jpeg', 'image/png'); // extensões permitidas
$maxSite = 1024 * 1024 * 5; // tamanho máximo da foto
$new_name = substr(sha1(time()).rand().md5(time()), - 40).".".$extensao; novo nome para imagem
for($i=0; $i < $numFoto; $i++){ //estrutura de repetição, só que isso vai adicionando várias linhas
if(move_uploaded_file($tmp, $folder.$new_name)){
$sqlInImg = mysqli_query($conn, "INSERT INTO postagem ( img, datePost) VALUES ('$new_name', NOW())");
if($sqlInImg == true){
$_SESSION['successPost'] = "Imagem postada com Sucesso";
header("Location: ../direcao.php");
}else{
unlink("../../arquivs/postagensImg/$new_name");
$_SESSION['errPost'] = "Desculpe, erro ao postar imagem";
header("Location: ../direcao.php");
}
}else{
$_SESSION['errPost'] = "Error ao adicionar imagem na pasta";
header("Location: ../direcao.php");
}
}
I will try to do here with the implode (), in case I can answer here like I did