title: Form boundaries and writing php://input to a file in php
body: <p>So I want users to be able to upload big files without having to worry about the post max size values.
  The alternative is using PUT and send a file as raw data.
  When using jquery I can do this:</p>
  
  <pre><code>var data = new FormData();
    jQuery.each($('#file_upload')[0].files, function(i, file) {
    data.append('file-'+i, file);
  });
  $.ajax({
    url: 'upload.php?filename=test.pdf',
    data: data,
    cache: false,
    contentType: false,
    processData: false,
    type: 'PUT',
  });
  </code></pre>
  
  <p>In PHP I can do this:</p>
  
  <pre><code>$f = fopen($_GET['filename'], "w");
  $s = fopen("php://input", "r");
  
  while($kb = fread($s, 1024))
  { 
    fwrite($f, $kb, 1024); 
  }
  fclose($f);
  fclose($s);
  Header("HTTP/1.1 201 Created");
  </code></pre>
  
  <p>I am not doing:</p>
  
  <pre><code>$client_data = file_get_contents("php://input");
  </code></pre>
  
  <p>Since putting the whole file into a variable will surely fill up all memory when uploading huge files.</p>
  
  <p>The thing I cannot figure out is how to write the file data without the form boundaries.
  Right now it writes at the top of the file something like this:</p>
  
  <pre><code>------WebKitFormBoundaryVz0ZGHLGxBOCUVQG
  Content-Disposition: form-data; name="file-0"; filename="somename.pdf"
  Content-Type: application/pdf
  </code></pre>
  
  <p>and at the bottom something like this:</p>
  
  <pre><code>------WebKitFormBoundaryVz0ZGHLGxBOCUVQG--    
  </code></pre>
  
  <p>So I need to parse the data. But for that I need to read the whole data stream into memory and with large video files I don't want to do that.
  I did read something about maybe creating a php://temp stream. But no luck yet with that.
  How can I write just the content to a file, without the boundary header? And without first pumping all the data into a variable?</p>