title: ajax send file and variable to php
body: <p>I'm using an ajax call to upload a file, handled by PHP. The file should be placed in a specific directory based on a jquery variable. I can get the file to upload, but cannot pass the variable along with the file. PHP reports an undefined index error.</p>
  
  <p>Ajax code:</p>
  
  <pre><code>var fd = new FormData();    
  fd.append( 'file', document.getElementById('select').files[0]);
  $.ajax({
      url: 'test.php',
      type: 'POST',
      data: fd,
      processData: false,
      contentType: false,
      success: function(e){
          // some code here
      }
  });     
  </code></pre>
  
  <p>I tried changing the data property to "fd+'&amp;myVar='+myVar, however PHP cannot parse the data correctly and returns undefined index error for both the $_FILES['file'] variable as well as the $_POST['myVar'] variable.</p>
  
  <p>How can I send both the file and a variable?</p>