douao1959 2017-07-22 05:41
浏览 41
已采纳

多个文件上载导致foreach()错误

Actually trying to upload multiple pictures in a folder at once with some kind of renaming. The upload goes to the foreach loop. However, it does stop at this point:

foreach ($_FILES['pictures']['name'] as $f => $name) {
        if ($_FILES['pictures']['error'][$f] == 0) {
            $name = $date;
            $name .= "-";
            $name .= $i;
            $name .= ".";
            $extsearch = $_FILES['pictures']['name'][$f];
            $ext = pathinfo($extsearch, PATHINFO_EXTENSION);
            $name .= $ext;
            if(move_uploaded_file($_FILES["pictures"]["tmp_name"][$f], $path.$name)) {
                if ($i == 1) {
                    create_image_thumb($albumFolder, $name);
                }
                $i++;
                resize_image($albumFolder, $name);
            }
        }
    }

However, I receive this error in the error_log and the files aren't moved:

PHP Warning:  Invalid argument supplied for foreach() in /home/clublabo/public_html/management/create_album_action.php on line 43

UPDATE: Here is the HTML Code:

<form class="form form-horizontal" action="create_album_action.php" method="post" enctype="multipart/form-data">
              <div class="form-group">
                <label for="email-2" class="col-sm-3 col-md-4 control-label">Date</label>
                <div class="col-sm-6 col-md-4">
                  <div class="input-with-icon">
                  <input name="dateAlbum" class="form-control" type="text" value="<?php echo date('Y-m-d'); ?>" data-provide="datepicker" data-date-autoclose="true" data-date-format="yyyy-mm-dd"><span class="icon icon-calendar input-icon"></span></div>
                </div>
              </div>
              <div class="form-group">
                <label for="password-2" class="col-sm-3 col-md-4 control-label">Pictures</label>
                <div class="col-sm-6 col-md-4">
                  <input name="pictures" id="password-2" class="form-control" type="file" multiple>
                </div>
              </div>
              <div class="form-group">
                <div class="col-sm-offset-3 col-sm-6 col-md-offset-4 col-md-4">
                  <button class="btn btn-primary pull-right" type="submit">Create Album</button>
                </div>
              </div>
            </form>

Maybe you guys has any Idea how to have this resolved?

Thanks :)

  • 写回答

2条回答 默认 最新

  • douxin8383 2017-07-22 06:40
    关注

    Replace:

    <input name="pictures" id="password-2" class="form-control" type="file" multiple>
    

    with:

    <input name="pictures[]" id="password-2" class="form-control" type="file" multiple>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?