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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化