Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing directory using codeigniter

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.

like image 853
webheadjay Avatar asked Jan 06 '13 02:01

webheadjay


1 Answers

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.

like image 55
The Alpha Avatar answered Oct 21 '22 18:10

The Alpha