Upload photos on Facebook using PHP

Posted: February 14, 2013 in Facebook

If you have strived for the uploading photos on Facebook via your site, then you are at right place. On demand of my readers I have written this article to show how to upload images on Facebook via PHP. First of all you need to create a Facebook app. I will not tell you how to do that. Get the appId and secret code of your application from facebook. This appId and secret code is necessary to connect you site to the application on Facebook. This code uses the Facebook.php class that can be downloaded from here.

WebSpeaks.in | Upload images to Facebook

$appId, //your facebook application id
‘secret’ => $secret, //your facebook secret code
‘cookie’ => true

$user = $facebook->getUser();

header(“Location:{$facebook->getLoginUrl(array(‘req_perms’ => ‘user_status,publish_stream,user_photos’))}”);
/******************Configuration options***********************/

$img = realpath($_FILES[“pic”][“tmp_name”]);
// allow uploads
$facebook->setFileUploadSupport(“http://” . $_SERVER[‘SERVER_NAME’]);
// add a status message
$photo = $facebook->api(‘/me/photos’, ‘POST’,
‘source’ => ‘@’ . $img,
‘message’ => ‘This photo was uploaded via http://www.WebSpeaks.in’

echo ‘

Click here to watch this photo on Facebook.


Select a photo to upload on Facebook.

Select the image:


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s