2013-05-15 2 views
3

사용자가 파일 입력을 복제하여 둘 이상의 파일을 추가 할 수있는 양식이 있습니다. 그러나 양식을 제출하고 'print_r ($ _ FILES)'을 사용하면 추가 한 파일 중 첫 번째 파일 만 표시됩니다.

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); }); 
}); 

});

내가 3 개 파일 인 print_r을 업로드하는 경우 ($ _ FILES) I 얻을

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)) 

이 왜 파일 만의 일이 아니라 그들 모두를 따기 다음 보여주는 하나 개의 파일 만? 나는 과거에 비슷한 일을 해왔고 지금까지 어떤 문제도 없었습니다. 어떤 도움이라도 대단히 감사하겠습니다! $ _FILES [ 'user_certificates]의

위해서 var_dump는 내가 만든이 테스트를 한 저에게이 (내가 3 개 파일을 업로드 후)

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 
+0

나는 형태의 외부 숨겨진 요소를 사용하고 복제. 각자 내가 생각하는 :). 'var_dump ($ _ FILES [ 'user_certificates']); 할 수 있습니까? –

+0

내 질문의 하단에 추가했습니다 – Pooshonk

+0

Javascript없이 세 파일 요소를 수동으로 추가하려고 했습니까? 양식이 수동으로 제출합니까? 아니면 jQuery/JS가 간섭합니까? –

답변

1

안녕을 제공합니다. 나를 위해 예상대로 작동! :)

문서 : 16562761.php

<?php 
if (!empty($_POST)) { 
    var_dump($_FILES);exit; 
} 
?> 
<html> 
    <head> 
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
    <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> 
    </head> 
    <body> 
    <form action="" method="post" enctype="multipart/form-data" id="add_personnel"> 
     <div id="certs_container"></div> 
     <p><button type="button" id="add_certificate">Add another certificate</button></p> 
     <p><button type="submit" id="submit">Submit</button></p> 
    </form> 
    <div style="display: none;" id="cloner"> 
     <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> 

    <script type="text/javascript"> 
    function add_clone() { 
     var clone = $('#cloner').html(); 
     $('#certs_container').append(clone); 
    } 

    $(function() { 
     add_clone(); 
     $('#add_certificate').click(function(e){ 
     add_clone(); 
     e.preventDefault(); 
     }); 
    }); 

    </script> 
    </body> 
</html> 
+0

이제 var_dump ($ _ FILES [ 'user_certificates'])는 아무 것도 표시하지 않는다. 혼란스러워 !!! 첫 번째 입력을 표시하지 않습니다. – Pooshonk

+0

전체 테스트로 편집했습니다. –

+0

약간의 연구가 끝나면 파일 입력 복제가 보안 ​​위험이 있으므로 제대로 작동하지 않을 것이라고 생각합니다. 귀하의 예를, 그것이 올바른 것처럼 보이지만, 그것은 여전히 ​​아무것도 보여주지 않습니다. 나는 이것에 시간 낭비보다는 오히려 대안을 생각해야 할지도 모른다 것을 나는 생각한다. 도움을 주셔서 감사합니다 :) – Pooshonk

관련 문제