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);
            }
        }
    }