Reputation: 51
I am trying to delete a file whose name is saved in $category_image
. But the function delete_files()
is not deleting.
public function deleteCategory($id,$category_image)
{
$this->load->helper('file');
//echo FCPATH.'/uploads/'.$category_image;
delete_files(FCPATH.'/uploads/'.$category_image,false,false);die;
//$this->load->model('AdminModel')->deleteCategory($id);
}
Upvotes: 1
Views: 2882
Reputation: 129
If you guys are looking for rest api unlink then
function delete_pres()
{
$this->load->helper('file');
$id = $this->input->get('id');
unlink(FCPATH.'./prescriptions/'.$id);die;
// if image on same location of code unlink(FCPATH.'../prescriptions/'.$id);die;
}
url : https://.../api/delete_pres?id=imagename.jpg
Upvotes: 0
Reputation: 8964
The problem is that delete_files()
is the wrong function to use. It is designed to "Deletes all files contained in the supplied directory path." - not to delete a single file. The addition of a file name at the end of the path causes the function to fail.
Just use unlink()
unlink(FCPATH.'uploads/'.$category_image);die;
Note that the constant FCPATH
already has a directory separator at the end so don't add another before 'uploads/'
.
Upvotes: 2