S.M_Emamian
S.M_Emamian

Reputation: 17383

How to delete a file using delete_files function of File Helper

I would like to delete a file in codeigniter. I want to use delete_files function, but it returns false !

    $this->load->helper("file");
    return delete_files(base_url().'application/cache/'.'blade-'.$cache_path);

Why it is returning false instead of deleting files.

Upvotes: 1

Views: 659

Answers (3)

elddenmedio
elddenmedio

Reputation: 1030

you need to change the path to the folder delete like

$this->load->helper('file');
return delete_files(APPPATH.'cache/'.'blade-'.$cache_path);

you don´t need to writte the url, coz the APPPATH places the pointer on the folder application, then you only specify in what subfolder you want to delete the file

Upvotes: 0

Shaiful Islam
Shaiful Islam

Reputation: 7134

use

$this->load->helper('file');
return delete_files(FCPATH.'application/cache/'.'blade-'.$cache_path);

Codeigniter delete_files function will delete files inside a directory and it returns true or false.

Returns:TRUE on success, FALSE in case of an error

You getting False means you have error.

Possible reasons for errors

  • Folder does not exists.
  • Folder path is not valid
  • Does not have proper permission

The files must be writable or owned by the system in order to be deleted.

For your case base_url().'application/cache/'.'blade-'.$cache_path is not a valid folder path.you added base_url before your folder name which will make the folder name like an URL. But It should be folder path.

Use FCPATH instead of base_url

Upvotes: 1

S.M_Emamian
S.M_Emamian

Reputation: 17383

Just use :

    return unlink(APPPATH.'cache/'.'blade-'.$cache_path);

Upvotes: 2

Related Questions