Q:

Twitter background upload with API and multi form data

Taken from the Twitter's API section.

Why do my image uploads always fail?
  The image update methods require
  multipart form data. They do not
  accept a URL to an image not do they
  accept the raw image bytes. They
  instead require the data to be
  delivered in the form of a file upload.

Has anyone came to a conclusion with this, or resolved this issue? I'm having various amounts of trouble trying to get it to post an image.
I've looked around and found no solutions with this.

A:

What exact problems are you having? From the sounds of the API, you just need to do a regular file upload to Twitter itself. The following allows you to upload a file to your server and push it to Twitter via the API docs:
<?php
    if( $_POST ) {
        // Do anything needed for authentication
        $ch = curl_init('http://twitter.com/account/update_profile_background_image.xml');
        curl_setopt_array(array(
            CURLOPT_POSTFIELDS => array('image' => '@'.$_FILES['myfile']['tmp_name']),
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST => true,
        ));

        $rsp = curl_exec($ch);
        // Read the response
    }
?>
<form enctype="multipart/form-data" method="post">
    File: <input type="file" name="myfile" />
    <input type="submit">
</form>

More information can be found in the PHP documentation and the cURL documentation for PHP.

