Delete uploaded image when I delete a record
- Single Page
Posted 02 May 2012 - 13:34 PM
when I delete a record with an image uploaded, the record is delete but the image is not delete!
How do I delete the image when the record is deleted?
Thenks a lot.
Sorry for my english.
D.
Posted 02 May 2012 - 14:02 PM
Posted 02 May 2012 - 18:45 PM
Posted 05 May 2012 - 02:17 AM
public function editevents(){
if (!$this->tank_auth->is_logged_in()) {
redirect('/auth/login/');
} else {
$this->load->library('grocery_CRUD');
$this->grocery_crud->set_table('event');
$this->grocery_crud->set_theme('datatables');
$this->grocery_crud->required_fields('eventtype','fileurl','header','description','date');
$this->grocery_crud->set_field_upload('fileurl','assets/uploads/files');
$this->grocery_crud->callback_after_upload(array($this,'example_callback_after_upload'));
$this->grocery_crud->callback_before_delete(array($this,'delete_event_pic_before_delete'));
$output = $this->grocery_crud->render();
$this->_events_output($output);
}
}
public function delete_event_pic_before_delete($primary_key)
{
$user= $this->db->where('eventid',$primary_key)->get('event')->row();
$url=base_url('assets/uploads/files').'/'.$user->fileurl;
unlink($url);
return true;
}
with out trying to add the delete before call back this worked perfectly. please help, thanks
Posted 05 May 2012 - 09:53 AM
$url= 'assets/uploads/files/'.$user->fileurl;
than
$url=base_url('assets/uploads/files').'/'.$user->fileurl;
So you will have:
public function delete_event_pic_before_delete($primary_key)
{
$user= $this->db->where('eventid',$primary_key)->get('event')->row();
$url= 'assets/uploads/files/'.$user->fileurl;
unlink($url);
return true;
}
Posted 05 May 2012 - 16:09 PM
Posted 10 March 2016 - 04:27 AM
image not delete from database when update time..plz help