I have a form which allows users to add more than one file by cloning the file input. However, when I submit the form and use 'print_r($_FILES)' it doesn't show up all of the files that I have added, only the first.
HTML:
<form action="admin/admin_area/save_personnel" method="post" enctype="multipart/form-data" id="add_personnel">
<div class="certificates_list">
<input type="file" name="user_certificates[]" />
<input type="text" name="certificate_name[]" class="right"/>
<input type="text" name="expiry_date[]" class="expiry_date" />
</div>
<div id="certificates_new"></div>
<p><button type="button" id="add_certificate">Add another certificate</button></p>
</form>
jQuery:
$(function() {
$('#add_certificate').click( function(event){
event.preventDefault();
var clone = $('.certificates_list:first').clone(true).appendTo('#certificates_new');
clone.find("input").val("");
clone.find(".expiry_date").datepicker('destroy').removeClass('hasDatepicker').removeAttr('id').datepicker({
dateFormat: 'dd-mm-yy',
yearRange: '1900',
changeMonth: true,
changeYear: true }).attr('name', 'expiry_date[]');
$(":input").each(function (i) { $(this).attr('tabindex', i + 1); });
});
});
If I upload 3 files and print_r($_FILES) I get the following showing only one file
Array ( [name] => Array ( [0] => license.txt ) [type] => Array ( [0] => text/plain ) [tmp_name] => Array ( [0] => C:\wamp\tmp\php42B1.tmp ) [error] => Array ( [0] => 0 ) [size] => Array ( [0] => 2496 ) )
Why is it only picking up one of the files and not all of them? I have done similar stuff in the past and I haven't had any problems up until now. Any help would be greatly appreciated!
var_dump of $_FILES['user_certificates] gives me this (after I uploaded 3 files)
array (size=5)
'name' =>
array (size=1)
0 => string 'license.txt' (length=11)
'type' =>
array (size=1)
0 => string 'text/plain' (length=10)
'tmp_name' =>
array (size=1)
0 => string 'C:\wamp\tmp\phpE11.tmp' (length=22)
'error' =>
array (size=1)
0 => int 0
'size' =>
array (size=1)
0 => int 2496