简体   繁体   中英

Update image with PHP PDO

Hello friends of the community, I'm uploading an image to the MySQL database, I have no problem everything works fine. But when I update the image goes blank as you can see in this picture: 在此处输入图片说明

This is the code I use to update records:

public function update($id,$fname,$lname,$email,$contact,$imagen,$fecha)
    {
        try
        {
            if(!empty($_FILES['imagen']['name'])){
                $nnombre=$_FILES['imagen']['name'];
                $ruta=$_FILES['imagen']['tmp_name'];
                $destino =  "img/productos/".$nnombre;
                $imagen = $nnombre;
                copy($ruta, $destino);
            }

            $stmt=$this->db->prepare("UPDATE productos SET first_name=:fname, 
                                                       last_name=:lname, 
                                                       email_id=:email, 
                                                       contact_no=:contact,
                                                       imagen=:imagen,
                                                       fecha=:fecha
                                                    WHERE id=:id");

            $stmt->bindparam(":fname",$fname);
            $stmt->bindparam(":lname",$lname);
            $stmt->bindparam(":email",$email);
            $stmt->bindparam(":contact",$contact);
            $stmt->bindparam(":imagen",$imagen, PDO::PARAM_STR);
            $stmt->bindparam(":fecha",$fecha);
            $stmt->bindparam(":id",$id);
            $stmt->execute();

            return true;

        }
        catch(PDOException $e)
        {
            echo $e->getMessage();  
            return false;
        }
    }

All it updated, but the image does not update.

I should do, please.

Instead of this one

$stmt->bindparam(":imagen",$imagen, PDO::PARAM_STR);

use

$stmt->bindparam(":imagen",$imagen, PDO::PARAM_BLOB);

Then, it will work fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM