简体   繁体   中英

How I can delete image from database and Image folder in CodeIgniter

I'm a beginner I'm facing issue related to the deletion of Image from my upload folder. My code is deleting just image name from database but not the Image from folder what I suppose to do.

My Model

public function delete_std($std_id,$std_image)
{
$this->db->where('std_id', $std_id);
unlink(FCPATH."uploads/".$std_image);
$this->db->delete('student'); 
}

My Controller

public function delete_std($std_id)
{
$this->load->model('std_model');
$this->std_model->delete_std($std_id,$std_image);
redirect('std_main/view_std');
}

Try this way

public function delete_std($std_id = '', $std_image = '')
{
    // Make sure $std_image is correct image.

    if (unlink(FCPATH . "/uploads/" . $std_image)) {

        $this->db->where('std_id', $std_id);
        $this->db->delete('student'); 

    }
}
if(unlink("upload+path/".'image_name');){
     $this->db->where('std_id', $std_id);
     $this->db->delete('student'); 
}

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