title: how to save remote image to a file using php curl?
body: <p>i am trying to save a remote image to a file using php curl but the file never get saved! could any one help me how to troublshoot this problem ? the image file never get created and but echo $returned_content has the data!</p>
  
  <pre><code> &lt;?
      $returned_content = get_data('http://somesite.com/43534545345dfsdfdsfdsfds.jpg');
  
      echo $returned_content;
  
      $fp = fopen('43534545345dfsdfdsfdsfds.jpg', 'w');
      fwrite($fp, $returned_content);
      fclose($fp);
  
  
      /* gets the data from a URL */
      function get_data($url) {
          $ch = curl_init();
          $timeout = 5;
          curl_setopt($ch, CURLOPT_URL, $url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
          curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
          $data = curl_exec($ch);
          curl_close($ch);
          return $data;
      }
  
  
  
  
      ?&gt;
  </code></pre>