title: Download csv file from server using curl in php
body: <p>I am struck with this. I want to download a csv file from url using curl. I have referred all the answer in stackoverflow and tried all. But not getting what i am expected. i have the following code.</p>
  
  <pre><code>define("COOKIE_FILE", "cookie.txt");
  $path = "settlement_file/test.csv";
  set_time_limit(0);
  $fp = fopen ($path, 'w+');//This is the file where we save the    information
  $ch = curl_init(str_replace(" ","%20",$url));//Here is the file we are downloading, replace spaces with %20
  curl_setopt($ch, CURLOPT_TIMEOUT, 50);
  curl_setopt($ch, CURLOPT_FILE, $fp); // write curl response to file
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
  curl_setopt ($ch, CURLOPT_COOKIEFILE, COOKIE_FILE); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSLVERSION,3);
  curl_exec($ch); // get curl response
  curl_close($ch);
  fclose($fp);
  </code></pre>