Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 525973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:43:40+00:00 2026-05-13T08:43:40+00:00

So far I have been trying to update the twitter profile bg image thr

  • 0

So far I have been trying to update the twitter profile bg image thr the twitter api with php… and without success

Many examples on the web, including this one:
Updating Twitter background via API
and this one
Twitter background upload with API and multi form data
do not work at all, most ppl throw out answers without actually testing the code.

I found that directly submit the image to the twitter.com thr html form, it will work:

<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>

(although the browser will prompt you for the twitter account username and password)

However, if I want to go thr the same process with php, it fails

<?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>

The strange thing of this code is that.. it successfully returns the twitter XML, WITHOUT having the profile background image updated. So at the end it still fails.

Many thanks for reading this. It will be great if you can help. Please kindly test your code first before throwing out answers, many many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:43:40+00:00Added an answer on May 13, 2026 at 8:43 am

    This is what works for me (debug stuff left in):

    $url      = 'http://twitter.com/account/update_profile_background_image.xml';
    $uname    = 'myuname';
    $pword    = 'mypword';
    $img_path = '/path/to/myimage.jpg';
    $userpwd  = $uname . ':' . $pword;
    $img_post = array('image' => '@' . $img_path . ';type=image/jpeg',
                      'tile'  => 'true');
    
    $opts = array(CURLOPT_URL => $url,
                  CURLOPT_FOLLOWLOCATION => true,
                  CURLOPT_RETURNTRANSFER => true,
                  CURLOPT_HEADER => true,
                  CURLOPT_POST => true,
                  CURLOPT_POSTFIELDS => $img_post,
                  CURLOPT_HTTPAUTH => CURLAUTH_ANY,
                  CURLOPT_USERPWD => $userpwd,
                  CURLOPT_HTTPHEADER => array('Expect:'),
                  CURLINFO_HEADER_OUT => true);
    
    $ch = curl_init();
    curl_setopt_array($ch, $opts);
    $response = curl_exec($ch);
    $err      = curl_error($ch);
    $info     = curl_getinfo($ch);
    curl_close($ch);
    
    echo '<pre>';
    echo $err . '<br />';
    echo '----------------' . '<br />';
    print_r($info);
    echo '----------------' . '<br />';
    echo htmlspecialchars($response) . '<br />';
    echo '</pre>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to get this jsfiddle to work. So far without luck.
I have been trying to use date_format , however as far as I know,
I've been trying for a whlie on this, and have so far been failing
I'm trying to intercept events using Gdk.Window.AddFilter(Gdk.FilterFunc) in Mono. So far, I have been
I'm trying to install bcrypt-ruby on Windows Vista. So far, I have been able
I am trying to connect to Webtrend's API using PHP but haven't been able
I have been trying this for a while and so far research has not
I'm a new user to knockout.js and so far have been very impressed with
So far I have been creating Web Portal but recently I had a request
I have been looking for a SSO system. So far I have found CAS.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.