codice:
  function rm($__filename){
   if(file_exists($__filename)){
     if (is_writable($__filename)){
       if(is_dir) {

                if ($handle = opendir($__filename)) {
                $i = 0;
                while (false != ($file = readdir($handle))) {
                   if ($file != "." && $file != "..") {
                    if (count(explode(".",$file)) > 1){ $_array[$i] = $file; }#end-if
                    $i += 1;
                   }#end-if
                 }#end-while
                  closedir($handle);
                }#end-if

                if (count($_array)!= 0){
                 while ($_tmp = each($_array)) {
                   unlink($__filename.'/'.$_tmp[1]);
                   $message = "tutti i file sono stati cancellati ";
                 }#end-while
                } else {
                   rmdir($__filename); #cancello la directory
                   $message = "la directory è stata cancellata ";
                }   #end-if
      } else { $message = "indicare il nome di una directory corretto"; } #end-if
  } else { $message = "la directory è protetta in scrittura ";}#end-if
  } else { $message = "la directory non esiste!";}#end-if
   return $message;
 }#end-if

 echo  rm('delme');
Ora divertiti!
penso all'incirca dovesse fare sta cosa qui quello che dovevi fare

l'ho adattata da una classe che avevo fatto da me è funzicata :P