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

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法