Recursive delete folders and subfolders

[html]
public function remove_dir($dir_name_based_on_script)
{
$dir_name_to_remove = dirname( $_SERVER['SCRIPT_FILENAME']) . ‘/’. $dir_name_based_on_script;

$this->recursiveDelete($dir_name_to_remove);
}
/**
* Delete a file or recursively delete a directory
*
* @param string $str Path to file or directory
*/
private function recursiveDelete($str){
if(is_file($str)){
return @unlink($str);
}
elseif(is_dir($str)){
$scan = glob(rtrim($str,’/').’/*’);
foreach($scan as $index=>$path){
$this->recursiveDelete($path);
}
return @rmdir($str);
}
}
[/html]