title: download a file from PHP Curl
body: <p>I have this code in my curl:
  $data_string = json_encode($data);                                                  </p>
  
  <pre><code>$ch = curl_init($url);                                                                      
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);                                                       
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
  curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
      'Content-Type: application/json; charset=utf-8',
      'User-Agent: '.$_SERVER['HTTP_USER_AGENT'],
      'X-Forwarded-For: '.$this-&gt;getIp()
  ));      
  
  $result = curl_exec($ch);
  return $result;
  </code></pre>
  
  <p>I am getting this giberish result:</p>
  
  <p><a href="https://i.stack.imgur.com/N9OHf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N9OHf.png" alt="enter image description here"></a></p>
  
  <p>I am expecting an image file.</p>
  
  <p>Question here is that how can i download this image file?</p>