-1

I use the following simple code to copy images from their URLs to my localhost/server; however it doesn't work when I use it with Facebook Graph API. For example:

 $url="http://graph.facebook.com/4/picture?type=large";
 copy($url,"newImageName.jpg");

Notes: No errors were shown. The image doesn't be uploaded.

How can I solve this issue?

DevManX
  • 476
  • 3
  • 14
  • what means "it does not work"? please be more specific. how about your error log? how did you get the user id? is it an app scoped id? – andyrandy Sep 10 '16 at 08:47
  • @luschn please look at the question again I edited it. Getting the user ID depends on Facebook Graph API. If you used the above URL, you would see Zuckerberg's image, but you can't copy it to your server (here is the problem). The code works fine with other -direct- images' URLs (eg: http://example.com/img.jpg). – DevManX Sep 10 '16 at 20:45
  • @luschn I found the solution in one of your previous answers, thank you man. – DevManX Sep 10 '16 at 23:41

1 Answers1

1

I found the solution in @luschn and @Joe answers. Thanks to both of them.

$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);  
$url="http://graph.facebook.com/userID/picture?type=large";
$data=file_get_contents($url, false, stream_context_create($arrContextOptions));
$fileName = 'fb_profilepic.jpg';
$file = fopen($fileName, 'w+');
fputs($file, $data);
fclose($file);
Community
  • 1
  • 1
DevManX
  • 476
  • 3
  • 14