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?
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);