Twitter API -> atualizando o perfil bg image com php

Até agora eu tenho tentado atualizar o perfil do Twitter bg imagem thr o twitter api com php ... e sem sucesso

Muitos exemplos na web, incluindo este:
Atualizando o plano de fundo do Twitter via API
e este
Upload de plano de fundo do Twitter com dados de API e vários formulários
não funciona de todo, a maioria ppl joga fora as respostas sem realmente testar o código.

Descobri que enviar diretamente a imagem para o formulário twitter.com thr html, vai funcionar:

<form action="http://twitter.com/account/update_profile_background_image.xml" enctype="multipart/form-data" method="post">
    File: <input type="file" name="image" /><br/>
    <input type="submit" value="upload bg">
</form>

(embora o navegador solicite o nome de usuário e a senha da conta do Twitter)

No entanto, se eu quiser ir pelo mesmo processo com php, ele falhará

<?php
if( isset($_POST["submit"]) ) {

    $target_path = "";
    $target_path = $target_path . basename( $_FILES['myfile']['name']); 

    if(move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
        // "The file ".  basename( $_FILES['myfile']['name']). " has been uploaded<br/>";
    } else{
        // "There was an error uploading the file, please try again!<br/>";
    }

    $ch = curl_init('http://twitter.com/account/update_profile_background_image.xml');
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($ch, CURLOPT_USERPWD, $_POST['name'] . ':' . $_POST['pass']);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
    curl_setopt($ch, CURLOPT_TIMEOUT, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => base64_encode(file_get_contents($target_path))));

    $rsp = curl_exec($ch);
    echo "<pre>" . str_replace("<", "&lt;", $rsp) . "</pre>";

}
?>
<form enctype="multipart/form-data" method="post">
<input type="hidden" name="submit" value="1"/>
name:<input type="text" name="name" value=""/><br/>
pass:<input type="password" name="pass" value=""/><br/>
File: <input type="file" name="myfile" /><br/>
<input type="submit" value="upload bg">
</form>

O estranho desse código é que ele retorna com sucesso o twitter XML,SEM ter a imagem de fundo do perfil atualizada. Então, no final, ainda falha.

Muito obrigado por ler isto. Vai ser ótimo se você puder ajudar. Por favor, gentilmente testar seu código antes de jogar fora as respostas, muitos muito obrigado.

questionAnswers(4)

yourAnswerToTheQuestion