title: How to use PHP/Curl to post a file to restful api?
body: <p>I'm trying to post avatar images from my website to pipedrive using PHP/Curl. The docs require a multipart/form-data encoding. I can't seem to get the actual file to post. I've tried several ways to send the file from various how-to's but every time pipedrive returns "no file attached". I've pasted my current attempt below, any ideas?  Or perhaps just point me to an example that would work?</p>
  
  <pre><code>$ch = curl_init();
  $timeout = 10;
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  curl_setopt($ch, CURLOPT_INFILESIZE, $params['filesize']);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_HTTPHEADER,
     array('Content-Type:multipart/form-data')
  );
  $data = curl_exec($ch);
  
  $params = array(
      'id' =&gt; $PDid,
      'file' =&gt; plugin_dir_path( dirname( __FILE__ )).'tmp/'.$filename,
      'filesize' =&gt; filesize(plugin_dir_path( dirname( __FILE__ )).'tmp/'.$filename)
  );
  </code></pre>