July 16, 2014 2:53 am

How to upload image on Facebook with Graph API using PHP

On demand of my readers I have written this tutorial on how can you upload an Image on Facebook using Graph API. This tutorial is a simple and easy to integrate on your website, we have already covers many features of Facebook Graph API like status of user or Page oAuth Login etc. This tutorial contains a live demo and complete demo source code download for free.

How to upload image on Facebook with Graph API using PHP

For its implementation and app creation you need to refer my previous tutorial How to Login with Facebook Graph API in PHP in this tutorial I have explained that how to create an app and configure it so you must check this before implementing this tutorial for complete understanding.

PHP Code

First of all this script shows you Facebook connect button when you click on it it will ask you for permission as shown in our tutorial How to Login with Facebook Graph API in PHP, after your authentication it will redirect to the same page with input field and an upload button. When you upload image it will save that image on server and after that it will run the Facebook image upload function with that image path.

The above code is used to upload image on facebook its very simple and easy to understand $image is an array contains access token, image path and message of image.  $facebook->setFileUploadSupport(true); used to set application for upload image, $facebook->api(‘/me/photos’, ‘POST’, $image); this function used to post image to /me/photos area.

I hope this tutorial helps you in your application please don’t forget to share it with your friends and subscribe or follow us on Twitter and Facebook for more updates.

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.

Tutorial Categories:
  • fondillusions

    Hi, this is for the old facebook sdk. Do you know how to do the same thing but using the latest facebook sdk? Thanks

  • ashulbha12

    when i upload the image it show this error : Call to undefined function exif_imagetype()

  • Amit

    When i uploaded image then it gives #324 (Requires uploaded file) error plz help me sir.

  • Its works without SSL server on normal shared hosting or must required SSL server?

    • huzoorbux

      it will work on both ssl and non ssl.

  • Max John

    I have just tested it on your server through the demo and after the upload, Facebook said

    This content is currently unavailable
    page you requested cannot be displayed right now. It may be temporarily
    unavailable, the link you clicked on may have expired, or you may not
    have permission to view this page.

    • huzoorbux

      Directory permission issue at my end fixed now please check

      • Max John

        Yep Now it is working. Wow. You guys are really a Gang of Php master lol

  • Deepak Gautam

    Sorry, there was a problem uploading your file please try again.

    error when i upload png format pic

    • HitendraRajput

      Same problem here , have u got the solution Deepak ?

  • Roshan

    Sorry, there was a problem uploading your file please try again.