duanchao9559 2013-05-15 10:03
浏览 41
已采纳

Codeigniter $ _FILES没有上传所有文件

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
  • 写回答

1条回答 默认 最新

  • duanjinchi1982 2013-05-15 10:34
    关注

    Hi I've created and tested this. Works as expected for me! :)

    Document: 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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂