Using my example below, I can delete a folder and the files it contains:
$uploaddir = "../img/uploads/".$destino_sa."/";
$dir_contents = scandir($uploaddir);
if(is_dir($uploaddir)) {
foreach($dir_contents as $content) {
unlink($uploaddir.'/'.$content);
rmdir($uploaddir);
}
}
However, when using the same example to delete a folder containing a subfolder and its files, I am not successful:
$uploaddir2 = "../img/uploads/hoteis/".$id_destino2."/".$destino_sa2."/";
$dir_contents2 = scandir($uploaddir);
if(is_dir($uploaddir2)) {
foreach($dir_contents2 as $content2) {
unlink($uploaddir2.'/'.$content2);
rmdir($uploaddir2);
}
}
It will then be seen that $destino
and $destino2
are completely different places, the last being that is causing me problems at the time of being removed. Here's an example of what I want to remove through $destino2
:
../img/uploads/hoteis/3/hotel_emiliano/
- hotel_emiliano folder and its contents
- 3 folder and its contents, in this case the
hotel_emiliano
How do I proceed?