首页 > 解决方案 > 无法从目录中删除图像,但数据已成功从 codeigniter 中的数据库中删除

问题描述

我无法从目录中删除图像,但数据成功从数据库中删除。请我需要帮助。

下面是我的控制器

public function hapus(){

   $id  = $this->input->get('id');

   /* query showing image for deleting image first before delete it from database */
   $path = './asset/uploads/';
   $path1 = './asset/hasil_resize/';
   $arraydelete  = array('id'=>$id);
   $rowdel = $this->Model_upldgbr->get_byimage($arraydelete);

   /* the image delete from folder */
   @unlink($path.$path1.$rowdel->namafile);


   $this->Model_upldgbr->get_delete($arraydelete); 
   $this->session->set_flashdata("pesan", "<div class=\"col-md-12\"><div class=\"alert alert-danger\" id=\"alert\">Success deleting the image and data !!</div></div>");
   redirect('root/upload');


 }

这是我的模型

function get_delete($where){
       $this->db->where($where);
       $this->db->delete($this->tabel);
       return TRUE;
    }
//function for showing data one by one from the table
    function get_byimage($where) {
        $this->db->from($this->tabel);
        $this->db->where($where);
        $query = $this->db->get();
        if ($query->num_rows() == 1) {
            return $query->row();
        }
    }
}

删除按钮链接是这样的:

 <a href="<?=base_url()?>index.php/root/upload/hapus/?id=<?=$row->id?>"><i class="fa fa-trash-o"></i></a>

标签: phpcodeignitercodeigniter-3delete-file

解决方案


希望对你有帮助 :

使用两种unlink方法从两个文件夹中删除文件FCPATH,应该是这样的

$path = FCPATH.'asset/uploads/';
$path1 = FCPATH.'asset/hasil_resize/';

@unlink($path.$rowdel->namafile); 
@unlink($path1.$rowdel->namafile);

//Or better use ci file helper's `delete_files()` method

更多信息:https ://www.codeigniter.com/user_guide/general/reserved_names.html


推荐阅读