Uploading multiple images in the same db column starts with comma

Asked

Viewed 24 times

1

The db record is starting with a comma.

The code begins with:

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

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

and then before recording on db:

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

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

  • It seems there’s a replace that trades dots for commas.

  • the code $imagens_nome = $imagens_nome.",".$NovoNome; appears to be correct. After all, the names are being concatenated. You can’t see in the above code, as is done the $NovoNome that is who is apparently generating the error. Show more code so we can help.

1 answer

1


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

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

I hope I’ve helped, any questions, just comment...

Browser other questions tagged

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