Upload Image using xmlrpc.php (SCRIPT!)

  • Author
    Posts
  • #460754

    karenchun
    Member

    Does anyone have a script (preferably php) that I can use to upload an image to my wordpress.com blog by calling xmlrpc.php?

    Example: take the image, http://www.desdelahabana.net/wp-content/uploads/2010/03/Sobreviviendo-en-el-socialismo-cubano-168×300.jpg and upload a copy of it to desdeaquifromhere.wordpress.com blog so that I can reference it in a post.

    Note: This is used in our wordpress.com blogs which are translations of Cuban bloggers because we want to preserve the images since they often go away in the original blog. Right now, we just reference the original image in our translated posts but that has resulted in losing images when the original Cuban post is moved or deleted.

    The blog I need help with is desdeaquifromhere.wordpress.com.

    #460941

    The metaWeblog.newMediaObject will work for uploading files via XML-RPC.

    #460952

    karenchun
    Member

    Thanks…I am looking at the docs for metaWeblog.newMediaObject but am a novice at using XML-RPC. So I understand the function call itself but not the overall way one would use it in a php script.

    Do you perhaps have some example code?

    #460959

    Using the IXR library that comes with WP it’s pretty easy:

    $data = array(
        'name'  => 'andy.avi',
        'type'  => 'video/x-msvideo',
        'bits'  => new IXR_Base64( dirname( __FILE__ ) . '/MVI_0649.AVI' )
    );
    
    $rpc = new IXR_Client( $rpc_url );
    $status = $rpc->query(
        'metaWeblog.newMediaObject',
        $blog_id,
        $username,
        $password,
        $data
    );

    You may want to try the WordPress.org support forums as well, there’s nothing specific to WordPress.com in this.

    #461006

    karenchun
    Member

    Many thanks!

The topic ‘Upload Image using xmlrpc.php (SCRIPT!)’ is closed to new replies.