lyl615 2018-10-16 01:13 采纳率: 33.3%
浏览 2347
已采纳

html多文件上传只有一个文件被上传

按ctrl同时选中多个文件同时上传,结果只有最后一个被选中的文件被上传,请问什么原因
图片说明
图片说明
图片说明
图片说明

  • 写回答

4条回答 默认 最新

  • Go 旅城通票 2018-10-16 01:51
    关注

    名字改为数组形式

     <form action="" method="post" enctype="multipart/form-data">
      Send these files:<br />
      <input name="upload[]" type="file" multiple /><br />
      <input type="submit" value="Send files" />
    </form>
    <?php
    print_r($_FILES["upload"]);
      ?>
    

    保存文件

    
    // Count # of uploaded files in array
    $total = count($_FILES['upload']['name']);
    
    // Loop through each file
    for($i=0; $i<$total; $i++) {
      //Get the temp file path
      $tmpFilePath = $_FILES['upload']['tmp_name'][$i];
    
      //Make sure we have a filepath
      if ($tmpFilePath != ""){
        //Setup our new file path
        $newFilePath = "./uploadFiles/" . $_FILES['upload']['name'][$i];
    
        //Upload the file into the temp dir
        if(move_uploaded_file($tmpFilePath, $newFilePath)) {
    
          //Handle other code here
    
        }
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条