I have form with input file which can be cloned by specific button.
when i choose some file, clone the input field, and choose new file (in the new input field) and submit, i'm not getting all the first file data in the ajax file.
Here is the html in the main page:
<a href="#" class="clone-ele-btn" data-target="clone_box" data-des="clone_des">Clone</a>
<form action="#" method="post" enctype="multipart/form-data">
<span id="clone_box">
<input type='file' name='file[]' />
</span>
<span id="clone_des"></span>
<a href="#" class="new-files-btn">Submit</a>
</form>
JQUERY:
// CLONE FILE INPUT FIELD
$(document).on("click", ".clone-ele-btn", function(e){
var target = $(this).data("target");
var des = $(this).data("des");
$( "#" + target ).clone().appendTo( "#" + des );
e.preventDefault();
});
// UPLOAD FILES
$(document).on("click", ".new-files-btn", function(e){
var form = $(this).closest('form')[0];
var formData = new FormData(form);
$.ajax ({
type: 'POST',
url: 'ajax/files-control.php',
data: formData,
dataType: 'json',
contentType: false,
cache: false,
processData:false
}).done(function(data)
{
....
...
..
files-control.php:
<?PHP
var_dump ($_FILES);
?>
NETWORK DEBUG:
C:\wamp3\www\folder\ajax\files-control.php:13:
array (size=1)
'file' =>
array (size=5)
'name' =>
array (size=2)
0 => string 'IMG_8913.JPG' (length=12)
1 => string 'I-dont-have.jpg' (length=36)
'type' =>
array (size=2)
0 => string '' (length=0)
1 => string 'image/jpeg' (length=10)
'tmp_name' =>
array (size=2)
0 => string '' (length=0)
1 => string 'C:\wamp3\tmp\php36B6.tmp' (length=24)
'error' =>
array (size=2)
0 => int 1
1 => int 0
'size' =>
array (size=2)
0 => int 0
1 => int 50906