简体   繁体   English

如何从CodeIgniter中的数据库和Image文件夹中删除图像

[英]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'); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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