Am having a hard time finding how to delete the actual image on my server before deleting its associated content from the database here is my callback
and below is my function that callback the above function
function delete_image_callback($primary_key){
$this->db->select('image'); $this->db->where('image_id', $primary_key); $image_name = $this->db->get('images')->row(); if(empty($image_name)){ return FALSE; } else { $image_path = base_url('assets/uploads/files/slides/'.$image_name->image); chmod($image_path, 0777); if(file_exists($image_path)){ if(unlink($image_path)){ return TRUE; } else { return FALSE; } } } }
My problem is the record in the database get deleted but not the image in the images folder and i can't figure out what is wrong with my logic
function images(){
$this->load->config('grocery_crud'); $this->config->set_item('grocery_crud_file_upload_allow_file_types', 'gif|jpeg|jpg|png'); $this->grocery_crud->set_table('mytable'); $this->grocery_crud->columns('title','image','caption'); $this->grocery_crud->set_theme('datatables'); $this->grocery_crud->required_fields('title','image'); $this->grocery_crud->set_field_upload('image','assets/uploads/files/slides'); $this->grocery_crud->callback_before_delete(array($this,'delete_images_callback')); $output = $this->grocery_crud->render(); $this->_news_output($output); }