Reply to Re: Update fields but keep previous image

Re: Update fields but keep previous image new!
by colin, 6 years, 4 months ago
Your code should be something like this:

$idNoticia = $_POST['idNoticia'];
$imagenNoticia_guardada = $_POST['imagenNoticia-guardada'];
$imagenNoticia = $_FILES['imagenNoticia'];
$tituloNoticia = $_POST['tituloNoticia'];
$noticiaCorta = $_POST['noticiaCorta'];
$noticiaCompleta = nl2br($_POST['noticiaCompleta']);

if (empty($imagenNoticia['name'])) {
    $imagenNoticia = $imagenNoticia_guardada;
} else {
    $upload = new Upload($imagenNoticia); 
    if ($upload->uploaded) {
      $upload->image_resize              = true;
      $upload->image_ratio               = true;
      $upload->image_x                   = 573; //ancho
      $upload->image_ratio_y             = true; //alto de acuerdo al ancho, mantiene perspectiva.
      $upload->image_watermark           = '../img/watermark.png';
      $upload->image_watermark_position  = 'TL';
      $upload->process('../img/noticias/');
      if ($upload->processed) {
        $imagenNoticia = $upload->file_dst_name;
      } else {
        // error!
      }
    } else {
      // error!
    }
}

$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
));
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