public static function recursiveRmdir($path, $removeParent = true)
    {
        if (!file_exists($path))
            return true;

        if (!is_dir($path))
            return @unlink($path);

        $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($objects as $item) {
            if ($item == '.' || $item == '..')
                continue;

            if(!is_dir($item))
            {
                if (!@unlink($item))
                    return false;
            } else {
                if(!@rmdir($item))
                    return false;
            }
        }
        return $removeParent ? rmdir($path) : true;
    }
public static function recursiveRmdir($path, $removeParent = true)
    {
        if (!file_exists($path))
            return true;

        if (!is_dir($path))
            return @unlink($path);

        $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($objects as $item) {
            if ($item == '.' || $item == '..')
                continue;

            if(!is_dir($item))
            {
                if (!@unlink($item))
                    return false;
            } else {
                if(!@rmdir($item))
                    return false;
            }
        }
        return $removeParent ? rmdir($path) : true;
    }
public static function recursiveRmdir ( $ path , $ removeParent = true ) { if ( ! file_exists ( $ path ) ) return true ; if ( ! is_dir ( $ path ) ) return @ unlink ( $ path ) ; $ objects = new RecursiveIteratorIterator ( new RecursiveDirectoryIterator ( $ path ) , RecursiveIteratorIterator :: CHILD_FIRST ) ; foreach ( $ objects as $ item ) { if ( $ item == '.' || $ item == '..' ) continue ; if ( ! is_dir ( $ item ) ) { if ( ! @ unlink ( $ item ) ) return false ; } else { if ( ! @ rmdir ( $ item ) ) return false ; } } return $ removeParent ? rmdir ( $ path ) : true ; }
Recursively remove a directory and its contents.

@param string  $path         The directory to remove
@param boolean $removeParent If false, then remove only the contents of the directory at $path.
Default: true

@return boolean true on success
Recursively remove a directory and its contents .