title: PHP cURL, read remote file and write contents to local file
body: <p>I want to connect to a remote file and writing the output from the remote file to a local file, this is my function:</p>
  <pre><code>function get_remote_file_to_cache()
  {
  
      $the_site=&quot;http://facebook.com&quot;;
  
      $curl = curl_init();
      $fp = fopen(&quot;cache/temp_file.txt&quot;, &quot;w&quot;);
      curl_setopt ($curl, CURLOPT_URL, $the_site);
      curl_setopt($curl, CURLOPT_FILE, $fp);
  
      curl_setopt($curl,  CURLOPT_RETURNTRANSFER, TRUE);
  
      curl_exec ($curl);
  
      $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
      if($httpCode == 404) {
          touch('cache/404_err.txt');
      }else
      {
          touch('cache/'.rand(0, 99999).'--all_good.txt');
      }
  
      curl_close ($curl);
  }
  </code></pre>
  <p>It creates the two files in the &quot;cache&quot; directory, but the problem is it does not write the data into the &quot;temp_file.txt&quot;, why is that?</p>