first of all we have to create an account on twitter and then we have to go on twitter developer account https://dev.twitter.com/apps. and create a twitter app for post. This is very simple, after filled all required fields your twitter application will be ready for use. After the creation of twitter app, we will get the CONSUMER_KEY, CONSUMER_SECRET, OAUTH_SECRET keys for entering in the index file.
Now ypu can use login with twitter and get oauth access token and oauth secret key for post on twitter account.
Now we can download the SDK from the GitHub. Here is the link for download SDK https://github.com/jublo/codebird-php.
require_once('Twitter/src/codebird.php');
\Codebird\Codebird::setConsumerKey(CONSUMER_KEY_XXXXX, CONSUMER_SECRET_XXXXXXXXX);
$cb = \Codebird\Codebird::getInstance();
$cb->setToken(OAUTH_ACCESS_TOKEN, OAUTH_SECRET_XXXXXXXX);
$image = "IMAGE_URL_TO_UPLOAD_ON_TWITTER";
$reply = $cb->media_upload(array(
'media' => $image
));
$mediaID = $reply->media_id_string;
$params = array(
'status' => 'MSG_FOR_TWEET',
'media_ids' => $mediaID
);
$cb->statuses_update($params);