title: How to upload files in Web Workers without using FormData
body: <p>How can I retrieve <code>$_FILES</code> in PHP when I upload through a Web Worker? When I tried to use <code>FormData</code>, I got the following error:</p>
  
  <blockquote>
    <p>Error: FormData is not defined</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><code>function uploadFile(blobFile, fileName, filePart, totalChunks) {
      //if I try to put this
      //var formData = new FormData(); //it does not work
      var xhr = new XMLHttpRequest();                
      xhr.open("POST", "upload.php"+"?"+"file="+fileName + filePart, true);
      xhr.onload = function(e) {};
      xhr.send(blobFile);
  }   
  </code></pre>
  
  <p>So in upload.php how am I supposed to get the tmp path from <code>$_FILES</code> ? Just in case, I will also show the page referencing the Web worker:</p>
  
  <pre><code>&lt;form id="fileuploader" enctype="multipart/form-data" method="post" action="upload.php"&gt;
      &lt;label for="fileToUpload"&gt;Select Files to Upload&lt;/label&gt;&lt;br /&gt;
      &lt;input type="file" name="fileToUpload[]" multiple="" id="fileToUpload" onchange="fileList();"/&gt;&lt;br /&gt;
      &lt;input type="button" onclick="sendRequest();" value="Upload" /&gt;
      &lt;!-- a place for File Listing --&gt;
      &lt;div id="fileList"&gt;&lt;/div&gt;           
  &lt;/form&gt;
  &lt;script type="text/javascript"&gt;
  function sendRequest() {
      var worker = new Worker("fileupload.js");
      worker.onmessage = function(e) {
          alert(e.data);
      }
      var file = document.getElementById('fileToUpload');
      for(var i = 0; i &lt; file.files.length; i++) { 
          worker.postMessage(file.files[i]);  
      }
  }
  </code></pre>