Here's a piece of code I found here
<?php
$dir_stack = array('test/'); // put the directory to delete here **NOTE** everything in this will be deleted.
$i = 0;
while ($i <= count($dir_stack)-1)
{
echo $dir_stack[$i].'<br>';
if ($dir = opendir($dir_stack[$i]))
{
while (false !== ($file = readdir($dir)))
{
if ($file != "." && $file != ".." && false == is_dir($dir_stack[$i].$file))
{
unlink($dir_stack[$i].$file);
}
elseif ($file != "." && $file != "..")
{
array_push($dir_stack,$dir_stack[$i].$file.'/');
}
}
closedir($dir);
}
$i++;
}
$i = count($dir_stack)-1;
while ($i >= 0)
{
rmdir($dir_stack[$i]);
$i--;
}
?>