Save Facebook Profile Photo


Hits: 3085  
<?php

$facebook_uid = '100000296428149';
$sourcecode = save_facebook_profile_photo($facebook_uid);

print_r($sourcecode);

file_put_contents("images/".$facebook_uid.".jpg", file_get_contents($sourcecode['url'])); //this is name of new file that i save

function save_facebook_profile_photo( $id )
{
    $options = array(
        CURLOPT_RETURNTRANSFER => true,     // return web page
        CURLOPT_HEADER         => false,    // don't return headers
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects
        CURLOPT_ENCODING       => "",       // handle all encodings
        CURLOPT_USERAGENT      => "spider", // who am i
        CURLOPT_AUTOREFERER    => true,     // set referer on redirect
        CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
        CURLOPT_TIMEOUT        => 120,      // timeout on response
        CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
    );
    
    $url = "http://graph.facebook.com/".$id."/picture";

    $ch      = curl_init( $url );
    curl_setopt_array( $ch, $options );
    $content = curl_exec( $ch );
    $err     = curl_errno( $ch );
    $errmsg  = curl_error( $ch );
    $header  = curl_getinfo( $ch );
    curl_close( $ch );

    //$header['errno']   = $err;
    //$header['errmsg']  = $errmsg;
    //$header['content'] = $content;
    print($header[0]);
    return $header;
}  

?>

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch

7 thoughts on “Save Facebook Profile Photo”

  1. Hey there would you mind stating which blog platform you’re using?

    I’m planning to start my own blog soon but I’m having a tough time deciding between BlogEngine/Wordpress/B2evolution and Drupal.

    The reason I ask is because your layout seems different then most blogs and I’m looking for something
    unique. P.S My apologies for being off-topic
    but I had to ask!

  2. Aw, this was a very nice post. Taking the time and actual effort to produce a very good article… but what can I say… I hesitate a whole lot and never seem to get nearly anything done.

Leave a Reply

Your email address will not be published.

*