title: PHP upload file with curl
body: <p>I'm trying to upload a file to an API with PHP. Additionally to the file i need to provide other parameters. My current code looks like this:</p>
  
  <pre><code>$ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $api_url);
  
  curl_setopt($ch, CURLOPT_PUT, 1);
  $post = array(
      'file'        =&gt; '@' . realpath('filename'),
      'other_parameter'  =&gt; ''
  );
  
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  curl_setopt($ch, CURLOPT_POST, 1);
  $headers = array('Content-Type: multipart/form-data');
  curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($ch, CURLOPT_USERPWD, $user . ":" . $pass);
  $result = curl_exec($ch);
  if (curl_errno($ch)) {
      echo 'Error:' . curl_error($ch);
  }
  curl_close ($ch);
  </code></pre>
  
  <p>Server header response:
  <code>
  HTTP/1.1 422 status code 422
  Cache-Control: no-cache
  Content-Type: application/json; charset=utf-8
  Status: 422 Unprocessable Entity
  Vary: Origin
  X-Content-Type-Options: nosniff
  X-Xss-Protection: 1; mode=block
  Content-Length: 106
  Connection: keep-alive</code></p>
  
  <p>Also i get the message that the file field cannot be empty.</p>