I want to delete the image not only in database, but in folder too.
this is my controller
public function delete_image($id)
{
$image_path = base_url().'uploads/images/gallery/'; // your image path
// get db record from image to be deleted
$query_get_image = $this->db->get_where('np_gallery', array('id' => $id));
foreach ($query_get_image->result() as $record)
{
// delete file, if exists...
$filename = $image_path . $record->picture;
echo $record->picture;
if (file_exists($filename))
{
unlink($filename);
}
// ...and continue with your code
$this->np_gallery_model->delete($id);
$query = $this->db->get("np_gallery");
$data['records'] = $query->result();
$this->load->view('admin/gallery/gallery_listing',$data);
}
}
i am able to delete from database but not from the folder
please use this code in your delete function
remove image path in your $filename.
$filename = $record->picture;
unlink("uploads/images/gallery/".$filename);
if (file_exists( base_url().'uploads/images/gallery/'.$filename))
{
unlink( base_url().'uploads/images/gallery/'.$filename);
}