public static function remove( $itemName )
    {
        $returnVar = true;
        if ( !is_dir( $itemName ) && file_exists( $itemName ) )
        {
            unlink( $itemName );
            return true;
        }

        if ( !file_exists( $itemName ) )
        {
            return true;
        }

        $dir = dir( $itemName );
        $item = $dir->read();
        while ( $item !== false )
        {
            if ( $item != '.' && $item != '..' )
            {
                self::remove( $dir->path . DIRECTORY_SEPARATOR . $item );
                $returnVar = false;
            }
            $item = $dir->read();
        }

        $dir->close();
        $returnVar = rmdir( $itemName ) && $returnVar ? true : false; // if rmdir succeeds and everything else succeeded
        return $returnVar;
    }
public static function remove( $itemName )
    {
        $returnVar = true;
        if ( !is_dir( $itemName ) && file_exists( $itemName ) )
        {
            unlink( $itemName );
            return true;
        }

        if ( !file_exists( $itemName ) )
        {
            return true;
        }

        $dir = dir( $itemName );
        $item = $dir->read();
        while ( $item !== false )
        {
            if ( $item != '.' && $item != '..' )
            {
                self::remove( $dir->path . DIRECTORY_SEPARATOR . $item );
                $returnVar = false;
            }
            $item = $dir->read();
        }

        $dir->close();
        $returnVar = rmdir( $itemName ) && $returnVar ? true : false; // if rmdir succeeds and everything else succeeded
        return $returnVar;
    }
public static function remove ( $ itemName ) { $ returnVar = true ; if ( ! is_dir ( $ itemName ) && file_exists ( $ itemName ) ) { unlink ( $ itemName ) ; return true ; } if ( ! file_exists ( $ itemName ) ) { return true ; } $ dir = dir ( $ itemName ) ; $ item = $ dir -> read ( ) ; while ( $ item !== false ) { if ( $ item != '.' && $ item != '..' ) { self :: remove ( $ dir -> path . DIRECTORY_SEPARATOR . $ item ) ; $ returnVar = false ; } $ item = $ dir -> read ( ) ; } $ dir -> close ( ) ; $ returnVar = rmdir ( $ itemName ) && $ returnVar ? true : false ; // if rmdir succeeds and everything else succeeded return $ returnVar ; }
Recursively removes a directory and its contents or a file.

Returns true on success and false on error.

@param string $itemName
@return bool
Recursively removes a directory and its contents or a file .