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.";
}
}
And then, you cannot store an upload object in $_POST['imagenNoticia-guardada']. Here, at best, you can keep the image file name, which you then will push back into your database.
Anyway, your issue is not related to the class itself, it is a PHP issue.Reply
Thanks for reply Colin. In my form my field ìmagenNoticia_guardada is a hidden field and there i have my image before.
I have my previous code without your class using move_upload_files and works perfectly but i need use your class. I don't know how implement. I can implement your class in my INSERT but I can't in UPDATE. Here is my previous code without class.upload.php
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.
And then, you cannot store an upload object in $_POST['imagenNoticia-guardada']. Here, at best, you can keep the image file name, which you then will push back into your database.
Anyway, your issue is not related to the class itself, it is a PHP issue.
In my form my field ìmagenNoticia_guardada is a hidden field and there i have my image before.
I have my previous code without your class using move_upload_files and works perfectly but i need use your class. I don't know how implement. I can implement your class in my INSERT but I can't in UPDATE.
Here is my previous code without class.upload.php
I will understand if you don't want reply me. But i don't know where write because is my third post in differents site and nobody help me :(
Thanks and congratulations for the class, is amazing!
Now I will try learn more about this and my issue.
THanks for all and sorry for my problems and my english!
greetings from Argentina!