title: Saving Facebook users profile picture to a folder
body: <p>I'm trying to save the profile pictures of my users into my server, but it only gives me a 0 byte jpg file whenever i execute my code.</p>
  
  <p>here is the first code that i tried but didn't work.</p>
  
  <pre><code>$fp = fopen ('fb_profilepic.jpg', 'w+');
  $ch = curl_init();
  curl_setopt ($ch, CURLOPT_URL, 'http://graph.facebook.com/875644792482183/picture');
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow the redirection
  curl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file
  curl_exec($ch); // get curl response
  curl_close($ch);
  fclose($fp);
  </code></pre>
  
  <p>this is the second code that i got from another thread</p>
  
  <pre><code>$fp = fopen ('fb_profilepic.jpg', 'w+');
  $ch = curl_init('http://graph.facebook.com/875644792482183/picture');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $json = '';
  if( ($json = curl_exec($ch) ) === false)
  {
      echo 'Curl error: ' . curl_error($ch);
  }
  else
  {
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow the redirection
      curl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file
      curl_exec($ch); // get curl response
      curl_close($ch);
      fclose($fp);
  
      echo 'Operation completed without any errors';
  }
  </code></pre>
  
  <p>both of them gives me a 0 byte jpg file.<a href="https://i.stack.imgur.com/IVreO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IVreO.png" alt="enter image description here"></a></p>