I´ve found this function and it works ;-) Maybe it will help you.
function delete($file) {
if (file_exists($file)) {
chmod($file,0777);
if (is_dir($file)) {
$handle = opendir($file);
while($filename = readdir($handle)) {
if ($filename != "." && $filename != "..") {
delete($file."/".$filename);
}
}
closedir($handle);
rmdir($file);
}
else {
unlink($file);
}
}
}
$nid = "3";
if($submit) {
$result = mysql_query("SELECT * FROM users WHERE id='$nid'");
$number = mysql_num_rows($result);
if($number) {
$fld = mysql_result($result, $i, "folder");
}
//sub directories
$fld_array = array("images","text","thb");
$count_fld = count($fld_array);
for($j=0; $j<$count_fld; $j++) {
$mydir = $fld . "/". $fld_array[$j];
delete ($mydir);
}
I tried your script and made some changes but I haven´t found the bug why it isn´t work so I tried to find some solving on the net and I found the function above ;-)
I think the sub directories in $fld_array could be in an alphabetical order.