public static function RecursiveRemoveDir($directory, $empty = false)
    {
        // if the path has a slash at the end we remove it here
        if(substr($directory, -1) == '/')
        {
            $directory = substr($directory, 0, -1);
        }

        // if the path is not valid or is not a directory ...
        if(!file_exists($directory) || !is_dir($directory))
        {
            return false;

            // ... if the path is not readable
        }
        elseif(!is_readable($directory))
        {
            return false;
        }
        else
        {
            $handle = opendir($directory);

            while(false !== ($item = readdir($handle)))
            {
                if($item != '.' && $item != '..')
                {
                    // we build the new path to delete
                    $path = $directory . '/' . $item;

                    // if the new path is a directory
                    if(is_dir($path))
                    {
                        self::RecursiveRemoveDir($path);

                        // if the new path is a file
                    }
                    else
                    {
                        if(!unlink($path))
                        {
                            return false;
                        }
                    }
                }
            }

            closedir($handle);

            if($empty == false)
            {
                if(!rmdir($directory))
                {
                    return false;
                }
            }

            return true;
        }
    }