Hi I m trying to create app that uses user's profile pic in it. So I write code that reads profile pic from facebook and save it on my server. I use following code
function GetImageFromUrl($link){
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_URL,$link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
return $result;
}
$userpicpath = "http://graph.facebook.com/$uid/picture?type=normal";
$sourcecode = GetImageFromUrl($userpicpath);
$savefile = fopen("$uid-normal.jpg", "w"); //this is name of new file that i save
fwrite($savefile, $sourcecode);
fclose($savefile);
Here $uid is id of user.
The above code doesn't work properly.
But when I copy the $userpicpath(ie http://graph.facebook.com/$uid/picture?type=normal) in browser and press enter it will return me new path to image in address bar and shows me proper image that I want. If i passed this new path in address bar to my function it saves image file that I want.
Why this is happening? How i get that second image path and pass it to my function in program. Please Help me.
Thanks.