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 up
You can do it using "delete_files" function:
$path = "the path that has files those will be deleted";
$this->load->helper("file"); // load codeigniter file helper
delete_files($path, true , false, 1); // second and the last parameters are required, second parameter should be true and the last parameter should be greater than 0
// Delete Directory
public function delete_directory($folderName)
{
$this->load->helper('file'); // Load codeigniter file helper
$dir_path = 'uploads/'.$folderName; // For check folder exists
$del_path = './uploads/'.$folderName.'/'; // For Delete folder
if(is_dir($dir_path))
{
delete_files($del_path, true); // Delete files into the folder
rmdir($del_path); // Delete the folder
return true;
}
return false;
}
$this->load->helper("file"); // load codeigniter file helper
delete_files('./path/to/directory/', TRUE); // Delete all files/folders in the dir
If you want to delete the empty folder(dir), add below line after above two lines
rmdir('./path/to/directory');
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.