Reply to Update fields but keep previous image

Update fields but keep previous image new!
by SoyDiego, 6 years, 4 months ago
Hi, thanks for reading.
I have a problem. I want Update my fields but when my input file is EMPTY, keep the previous image that I uploaded before. Work perfectly when I upload a new picture and update all fields but when I only update the fields and keep my image before, nothing happen. This is my code:

$idNoticia = $_POST['idNoticia'];
$imagenNoticia_guardada = $_POST['imagenNoticia-guardada']; //image before 
$tituloNoticia = $_POST['tituloNoticia'];
$noticiaCorta = $_POST['noticiaCorta'];
$noticiaCompleta = nl2br($_POST['noticiaCompleta']);
$imagenNoticia = new upload($_FILES['imagenNoticia']); //new image


if (empty($imagenNoticia)) {
  $imagenNoticia = $imagenNoticia_guardada; //I THINK THE PROBLEM IS HERE.
}

if ($imagenNoticia->uploaded) {
  $imagenNoticia->image_resize              = true;
  $imagenNoticia->image_ratio               = true;
  $imagenNoticia->image_x                   = 573; //ancho
  $imagenNoticia->image_ratio_y             = true; //alto de acuerdo al ancho, mantiene perspectiva.
  $imagenNoticia->image_watermark           = '../img/watermark.png';
  $imagenNoticia->image_watermark_position  = 'TL';

  $imagenNoticia->process('../img/noticias/');
  if ($imagenNoticia->processed) {

    $statement = $conexion->prepare("UPDATE noticias SET tituloNoticia = :tituloNoticia, noticiaCorta = :noticiaCorta, noticiaCompleta = :noticiaCompleta, imagenNoticia = :imagenNoticia WHERE idNoticia = $idNoticia"
  );
  
    $statement->execute(array(
        ':tituloNoticia' => $tituloNoticia,
        ':noticiaCorta' => $noticiaCorta,
        ':noticiaCompleta' => $noticiaCompleta,
        ':imagenNoticia' => $imagenNoticia->file_dst_name
    ));

    echo "La noticia ha sido editada correctamente.";
  }
}

Thanks, and sorry for my english.Reply

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important