title: Manually parse raw multipart/form-data data with PHP
body: <p>I can't seem to find a real answer to this problem so here I go:</p>
  
  <p>How do you parse raw HTTP request data in <code>multipart/form-data</code> format in PHP? I know that raw POST is automatically parsed if formatted correctly, but the data I'm referring to is coming from a PUT request, which is not being parsed automatically by PHP. The data is multipart and looks something like:</p>
  
  <pre><code>------------------------------b2449e94a11c
  Content-Disposition: form-data; name="user_id"
  
  3
  ------------------------------b2449e94a11c
  Content-Disposition: form-data; name="post_id"
  
  5
  ------------------------------b2449e94a11c
  Content-Disposition: form-data; name="image"; filename="/tmp/current_file"
  Content-Type: application/octet-stream
  
  �����JFIF���������... a bunch of binary data
  </code></pre>
  
  <p>I'm sending the data with libcurl like so (pseudo code):</p>
  
  <pre><code>curl_setopt_array(
    CURLOPT_POSTFIELDS =&gt; array(
      'user_id' =&gt; 3, 
      'post_id' =&gt; 5, 
      'image' =&gt; '@/tmp/current_file'),
    CURLOPT_CUSTOMREQUEST =&gt; 'PUT'
    );
  </code></pre>
  
  <p>If I drop the CURLOPT_CUSTOMREQUEST bit, the request is handled as a POST on the server and everything is parsed just fine.</p>
  
  <p>Is there a way to manually invoke PHPs HTTP data parser or some other nice way of doing this?
  And yes, I have to send the request as PUT :)</p>