Written by Saran on February 15, 2012, Updated December 21, 2013
Posting pictures on Facebook works similar as Posting to Facebook Page Wall, you can post not just photos, but questions, status, notes etc in a similar way. In previous post we have seen how we can post a photo to page wall by specifying its relative path, but in this tutorial we will upload picture and directly post to user profile page using an upload form.I have created 3 PHP files in similar manner as before, index.php, config.php and process.php. Index.php contains an image upload field and message box. Once user clicks on upload photo, the data is sent to process.php and if everything seems ok, the uploaded picture will appear in users' profile wall.
Configuration
As before the config.php file contains App ID, App Secret, return url, home url and permissions required. Just replace them with your application details and URLs. Also remember the line 'fileUpload' => true while initializing the SDK, it sets File Upload support in facebook SDK.[cc lang="php"] $appId, 'secret' => $appSecret, 'fileUpload' => true, 'cookie' => true )); $fbuser = $facebook->getUser(); ?> [/cc]
Upload Form
Users are redirected to facebook authentication page, where users grant two permissions publish_stream and user_photos. And then users are presented with upload form, and once user selects a picture and clicks upload, the post data is sent to process.php.[cc lang="html"] destroySession(); header("Location: ".$homeurl); }if(!$fbuser) { $fbuser = null; $loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions)); echo '';}else{?>Post Photos to User Profile