How to post all file in the list? | Jquery - PHP -


i have script (index.php) create list of added files "browse file" button. , have script (process.php) send files on list email phpmailer.

my problem is, file(s) @ last click sent. file(s) have been added unsent.

index.php script

<html> <head>     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> </head> <body> <form id="data" action="process.php" method="post" enctype="multipart/form-data">     <input id="file" type="file" name="files[]" multiple="multiple"/>     <div id="output"><ul></ul></div>     <input type="submit" name="submit" value="ok"> </form> </body> <script> $("#file").change(function() {     var ele = document.getelementbyid($(this).attr('id'));     var result = ele.files;     for(var x = 0; x < result.length; x++){         var file = result[x];         $("#output ul").append("<li>" + file.name + "</li>");        } }); </script> </html> 

process.php script

<?php require 'mail/phpmailerautoload.php';  $to = 'destination@email.com'; $subject = 'test';  if(isset($_post['submit'])){ $attachment_name = $_files['files']['name']; $attachment_type = $_files['files']['type']; $attachment = $_files['files']['tmp_name'];  include 'smtp.php';  $mail->addaddress($to); $mail->subject = $subject; $mail->msghtml('tes');  foreach($attachment_name $key => $att){     $nama_file = $attachment_name[$key];     $tmp_file = $attachment[$key];      $mail->addattachment($tmp_file, $nama_file); }  if (!$mail->send()) {     echo '<script>alert("fail"); </script>'; } else {     echo '<script>alert("success"); </script>'; } } ?> 

assume have success create multiple input tag upload file. (using jquery)

and @ php side:

// first file $_files['files']['name'][0]; $_files['files']['type'][0]; $_files['files']['tmp_name'][0];  // second file $_files['files']['name'][1]; $_files['files']['type'][1]; $_files['files']['tmp_name'][1]; 

or:

$total = count($_files['upload']['name']);  // loop through files for($i = 0; $i < $total; $i++) {     $_files['files']['name'][$i];     //do want }