The rmdir() function fails if the folder contains any files. I can loop through all of the the files in the directory with something like this:
This fuction delete the directory and all subdirectories and files:
function DelDir($target) {
if(is_dir($target)) {
$files = glob( $target . '*', GLOB_MARK ); //GLOB_MARK adds a slash to directories returned
foreach( $files as $file )
{
DelDir( $file );
}
rmdir( $target );
} elseif(is_file($target)) {
unlink( $target );
}
}