class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
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.";
}
}
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:
Thanks, and sorry for my english.