public static function removeFolder($folder, $contentsOnly = false)
    {

        // remove a file encountered by a recursive call.
        if (is_file($folder) || is_link($folder)) {
            unlink($folder);
        } else {
            $dir = opendir($folder);
            while ($file = readdir($dir)) {
                if (($file == '.' || $file == '..')) {
                    continue;
                } else {
                    self::removeFolder($folder . '/' . $file);
                }
            }
            closedir($dir);
            if (!$contentsOnly) {
                rmdir($folder);
            }
        }
    }
public static function removeFolder($folder, $contentsOnly = false)
    {

        // remove a file encountered by a recursive call.
        if (is_file($folder) || is_link($folder)) {
            unlink($folder);
        } else {
            $dir = opendir($folder);
            while ($file = readdir($dir)) {
                if (($file == '.' || $file == '..')) {
                    continue;
                } else {
                    self::removeFolder($folder . '/' . $file);
                }
            }
            closedir($dir);
            if (!$contentsOnly) {
                rmdir($folder);
            }
        }
    }
public static function removeFolder ( $ folder , $ contentsOnly = false ) { // remove a file encountered by a recursive call. if ( is_file ( $ folder ) || is_link ( $ folder ) ) { unlink ( $ folder ) ; } else { $ dir = opendir ( $ folder ) ; while ( $ file = readdir ( $ dir ) ) { if ( ( $ file == '.' || $ file == '..' ) ) { continue ; } else { self :: removeFolder ( $ folder . '/' . $ file ) ; } } closedir ( $ dir ) ; if ( ! $ contentsOnly ) { rmdir ( $ folder ) ; } } }
Remove a directory and all subdirectories and files.

@param String $folder Absolute folder path
@param Boolean $contentsOnly If this is true then the contents of the folder will be removed but not the
folder itself
Remove a directory and all subdirectories and files .