I'm new to codeigniter so please forgive me, I am trying to make codeigniter delete a base folder (I don't know what the right term is, it's the folder where I put my uploaded files and its located in the root of my codeigniter project). Since I am new to codeigniter, I don't have any idea on how to make use of the File Helper reference in the codeigniter api. I hope someone can help me with this.
Furthermore, the delete function I am trying to make needs to delete also all of its contents, so empty or not, the folder gets deleted. I'm guessing, it would use a recursive type of deletion...I'm not so sure at all.
You can delete all files using delete_files function
$path=$this->config->base_url().'dir_name';
$this->load->helper("file"); // load the helper
delete_files($path, true); // delete all files/folders
Above code will delete all files and folders from the given path and if once the directory is empty then you can use rmdir which deletes an empty directory, like
rmdir($path);
The folder should permit relevant permissions, which means files/folder must be writable or owned by the system in order to be deleted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With