Upload multiple images in same column db starts with comma

1

The record in db is beginning with a comma.

The code begins with:

$imagens_nome ="";
foreach($_FILES as $file)....

Upload and create thumbnail ... Generates a new name: $ NewName

and then before writing to db:

 $imagens_nome = $imagens_nome.",".$NovoNome;

However I think the above part $ images_name ... is wrong, because in db it looks like this: column photos:, 7263273813.jpg, 737862834.jpg, 236276322.jpg

    
asked by anonymous 13.04.2017 / 16:40

1 answer

1

From what I understand the only problem is that you are going with an extra comma because of its concatenation form, right? One way to solve this is to make a new string starting from the second character, since the first one is always a comma, this before writing to bd. This way:

<?php
$imagens_nome = ",7263273813.jpg,737862834.jpg,236276322.jpg";
$imagens_nome=substr($imagens_nome,1,strlen($imagens_nome));
?>

I hope to have helped, any questions, just comment ...

    
13.04.2017 / 17:35