title: XMLHTTPREQUEST send file and parameters
body: <p>i am trying to send a file through xmlhttprequest and process it on the server through PHP, i <strong>cannot</strong> use jQuery.</p>
  
  <p>Here is my javascript</p>
  
  <pre><code>xhr = new XMLHttpRequest();
  xhr.open("POST", $("upload").action, true);
  xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  xhr.setRequestHeader("X_FILENAME", file.newname || file.name);
  xhr.setRequestHeader("CONTENT_TYPE", file.type);
  xhr.send("userfile=" + file + "&amp;" + $('upload').serialize());
  </code></pre>
  
  <p>it happens that on my PHP the $_FILES is empty and the $_POST along with the form data holds the variable userfile which is marked as "object file".</p>
  
  <p>So now my questions are:</p>
  
  <ol>
  <li>Does the variable userfile really holds the content of the file i am trying to upload?</li>
  <li>How can i copy the value in userfile to a file on my server?</li>
  </ol>
  
  <p>This is what I tried so far:</p>
  
  <pre><code>file_put_contents($tmpfile, $userfile);
  </code></pre>
  
  <p>but it does not seem to copy correctly the value into $tmpfile.</p>
  
  <p>I hope I was clear enough</p>
  
  <p>Thanks in advance </p>
  
  <p>Best regards</p>