1) this is my controller code to delete an image. But when I do this, the image gets deleted from website, database and image folder. But there I get an error message.
public function delete_slide_group1($slide_group1_id) {
$slide_group1_info = $this->sa_model- >display_slide_group1_details_by_slide_group1_id($slide_group1_id);
$image_path = explode(base_url(), $slide_group1_info->slide_group1_links, 2);
unlink($image_path[1]);
$this->sa_model->delete_slide_group1_by_slide_group1_id($slide_group1_id);
$data['message'] = "Data deleted Successfully";
$this->session->set_userdata($data);
redirect('super_admin/slide_group1');
}
2) BUT When I do this, my images get deleted from database and website, but not deleted from image folder. And there I don't get any error message. What should be changed in my code?
public function delete_product($product_id) {
$this->sa_model->delete_product_image_by_product_id($product_id);
$sdata = array();
$sdata['message'] = 'Deleted Successfully !';
$this->session->set_userdata($sdata);
redirect('super_admin/view_all_product');
}
To delete the file you must to use the unlink php function.
An example could be:
if (file_exists($filename)) {
unlink($filename);
echo 'File '.$filename.' has been deleted';
} else {
echo 'Could not delete '.$filename.', file does not exist';
}
Remember the $filename contain also the path of the file. For any info you can have a look on http://php.net/manual/en/function.unlink.php