Update of Multiple Images

2

My code is currently playing its part well up and putting the watermark on upload images, but I would like to be storing the names of all images in the database.

$idnoticia = $_GET['idnoticia'];

$watermark = imagecreatefrompng('watermark.png');
$watermark_x = imagesx($watermark);
$watermark_y = imagesy($watermark);
$dir = "../img/$idnoticia/";

foreach($_FILES['files']['tmp_name'] as $index => $file) {
   $image = imagecreatefromjpeg($file);
   imagecopy($image, $watermark, round(imagesx($image) / 1) - round($watermark_x / 1),    round(imagesy($image) / 1) - round($watermark_y / 1), 0, 0, $watermark_x,    $watermark_y);
   imagejpeg($image, $dir . preg_replace('/.jpeg|.jpg/i', '', $_FILES['files']['name'][$index]) . '_wm.jpg');
   imagedestroy($image);
}

imagedestroy($watermark);
echo "Envio Completado!";

$sqlInsert = 'UPDATE noticias SET galeria = "$image" WHERE idnoticia = "$idnoticia';
$stmt = DB::prepare($sqlInsert2);
$stmt->bindParam("galeria", $image);
$stmt->execute();

I would like to store the names of the images in the galeria field as (img1.jpg, img2.jpg, img3.jpg), placing a delimiter for when to display facilitate.

Is it possible?

    
asked by anonymous 06.04.2015 / 15:17

1 answer

1

First store names in an array while running your foreach:

$nomes = array();
foreach($_FILES['files']['tmp_name'] as $index => $file) {
    (...)
    $nomes[] = $_FILES['files']['name'][$index]) . '_wm.jpg';
}

At the time of saving, concatenate using the implode function, in the example having a comma and a space as the separator:

link

$sqlInsert = 'UPDATE noticias SET galeria = "'.implode(', ', $nomes).'"  WHERE idnoticia = "$idnoticia';

I hope I have helped.

    
06.04.2015 / 15:30