⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

calll bck before delete



PunkMaster
  • profile picture
  • Member

Posted 19 May 2013 - 08:07 AM

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); 
}

PunkMaster
  • profile picture
  • Member

Posted 19 May 2013 - 08:18 AM

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

 

 

 

 

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;
            }

        } 
    }
}

and below is my function which callback the above function

 

 

 

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); 
}

 

 

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


davidoster
  • profile picture
  • Member

Posted 19 May 2013 - 09:30 AM

Simple spelling mistake I think!

$this->grocery_crud->callback_before_delete(array($this,'delete_images_callback'));

and the function is called, function delete_image_callback($primary_key)


PunkMaster
  • profile picture
  • Member

Posted 20 May 2013 - 08:06 AM

I did correct the spelling but the images are still not deleted


davidoster
  • profile picture
  • Member

Posted 20 May 2013 - 11:22 AM

Check the logs to see what happens.

Maybe you need to chmod from the prompt.