title: how to append multiple files input on formdata
body: <p>I have to send multiple files using form data but my code is not working can anybody tell me where it is wrong.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$('#fileupload').on('change', function() {
    var to_user_id = $(this).data('touserid');
    var chat_id = $(this).data('chat_id');
    var formData = new FormData();
    $.each($('input[type=file]')[0].files, function(i, value) {
      formData.append('file[' + i + ']', value.files[0]);
    });
    //console.log(formData);
    formData.append('to_user_id', to_user_id);
    formData.append('chat_id', chat_id);
    $.ajax({
      url: 'upload.php',
      type: 'POST',
      data: formData,
      dataType: 'json',
      processData: false,
      contentType: false,
      cache: false,
      success: function(data) {
        //console.log(data);
      }
    })
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;form method="post" name="upload_form" id="upload_form" enctype="multipart/form-data" action="upload.php"&gt;
    &lt;input type="file" name="fileupload[]" id="fileupload" multiple data-touserid="'+to_user_id+'" data-chat_id="'+getdata+'"&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>