I create in my project a directory with subdirectories and files. After I do my duty with files content I want to delete the entire folder(all the subdirectories, files and main directory).
I use ZF2 framework and this is my function:
public function recursiveRemoveDirectory($directory) {
foreach(glob("{$directory}/*") as $file) {
if(is_dir($file)) {
$this->recursiveRemoveDirectory($file);
} else {
unlink($file);
}
}
rmdir($directory);
}
and I call this function in this way:
$this->recursiveRemoveDirectory($dirPath);
My function erase all contents(subdirectories and files) of the directory but not the directory.
I see that already exist questions on this topic, but I didn't find the solution.