简体   繁体   中英

How to delete image from database codeigniter?

This my controller:

public function doDelete($id_jeans)
{
    $where = array("id_jeans" => $id_jeans);
    $res = $this->admin_model->DeleteData('jeans', $where);
}

This my model:

public function DeleteData($tabelname, $where)
    {
        if ($this->db->delete($tabelname, $where)) {
            redirect("admin/admin/index");
        }else {
            echo "tidak berhasil";
        }
        $res = $this->db->delete($tabelname, $where);
        return $res;            
    }

How can I delete an image with CodeIgniter?

You are only removing data from a table. If you want to delete a file from a directory:

public function DeleteData($tabelname, $where, $path_to_file)
{
    if ($res = $this->db->delete($tabelname, $where)) {
        unlink($path_to_file);
        redirect("admin/admin/index");
    }else {
        echo "tidak berhasil";
    }           
}

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