title: CURL: Send images with boundary to REST API
body: <p>Im currently working with some kind of API. I have wrote simple functions which allows me to add new content, however Im stuck on uploading images.</p>
  
  <p>Here's simple CURL command in documentation:</p>
  
  <pre><code>curl -v -s -u username:password \
    -H "Content-Type: multipart/form-data" \
    -H "Accept: application/api+json" \
    -F "image=@img1.jpeg;type=image/jpeg" \
    -F "image=@img2.jpeg;type=image/jpeg" \
    -XPUT ''
  </code></pre>
  
  <p>And a sample REQUEST:</p>
  
  <pre><code>PUT /images HTTP/1.1
  Host: example
  Content-Type: multipart/form-data; boundary=vjrLeiXjJaWiU0JzZkUPO1rMcE2HQ-n7XsSx
  
  --vjrLeiXjJaWiU0JzZkUPO1rMcE2HQ-n7XsSx
  Content-Disposition: form-data; name="image"; filename="img1.jpg"
  Content-Type: image/jpeg
  Content-Transfer-Encoding: binary
  </code></pre>
  
  <p>Now, there is my function:</p>
  
  <pre><code>$headers_put = array( 
     "Content-Type: multipart/form-data; boundary=vjrLeiXjJaWiU0JzZkUPO1rMcE2HQ-n7XsSx",
     "Accept: application/+json",  
  ); 
  
  function putImages($ch, $headers, $ad, $images){
      $url = '/images';
  
      $files = [];
  
      foreach($images as $key =&gt; $image) {
          $number = $key +1;
          $paths = parse_url($image, PHP_URL_PATH);
          $paths = $_SERVER['DOCUMENT_ROOT'] . $paths;
  
          $cfile = new CURLFile(''. $paths, 'image/jpeg', 'image'.$key);
          $files[$key] = $cfile;
  
      }
  
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
      curl_setopt($ch, CURLOPT_POSTFIELDS, $files);
  
      $result = curl_exec($ch);
      var_dump($result);
  
      echo curl_getinfo($ch, CURLINFO_HTTP_CODE);
      echo "\n";
  
  }
  </code></pre>
  
  <p>Finally, the response is:</p>
  
  <pre><code>{"errors":{"error":{"@key":"unsupported-form-element"}}}"
  </code></pre>
  
  <p>What Im doing wrong? Any ideas? Thank you kindly for any help.</p>