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:
One safe and good function located in php comments by lprent It prevents accidentally deleting contents of symbolic links directories located in current directory
public static function delTree($dir) {
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file) {
(is_dir("$dir/$file") && !is_link($dir)) ? delTree("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}