Suppose that 'Demo,hello.php,Chrysanthemum.jpg' is an array of directories and files that i want to delete in which demo is a directory containing directories and files.The following piece of code gives me this error.
Warning: rmdir(Demo): Directory not empty in C:\xampp\htdocs\file.php on line 32
please help me debugging this problem.
<?php
$arr = explode(',' ,'Demo,hello.php,Chrysanthemum.jpg');
$len = count($arr);
$i = 0;
$directory = array();
/*while($i < $len){
$arr[$i] = '../uploads/'.$arr[$i];
$i++;
}*/
while(count($arr) > 0){
$dir = array_pop($arr);
if(is_dir($dir)){
array_push($directory ,$dir);
$dh = opendir($dir);
while(($file = readdir($dh)) !== false){
if($file != '.' && $file != '..'){
if(is_dir($dir.'/'.$file)){
array_push($arr ,$dir.'/'.$file);
}
else{
unlink($dir.'/'.$file);
}
}
}
}
else{
unlink($dir);
}
}
while($dir = array_pop($directory)){
rmdir($dir);
}
?>