【问题标题】:Error when uploading multiple files in Codeigniter在 Codeigniter 中上传多个文件时出错
【发布时间】:2012-03-07 13:48:29
【问题描述】:

我尝试在 CodeIgniter 中使用多个文件上传,但出现错误: You did not select a file to upload.

我的html代码:

<input type="file" id="ModelImage" name="ModelImage[]" multiple="multiple"  value=""/>

我的php代码:

for($i = 0; $i < count($_FILES['ModelImage']["name"]); $i++)
{
  if (!empty($_FILES['ModelImage']['name'][$i]))
  {
    $config['upload_path'] = './uploads/starmodel/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['file_name']= "star_".$lastid."_".$i.strrchr(basename($_FILES["ModelImage"]["name"][$i]),".");
    $this->upload->initialize($config);

    if ($this->upload->do_upload('ModelImage'))
    {
      $data = $this->upload->data();
      $udata = array('ModelImage' => $config['file_name']);
      $this->db->where('ModelID', $lastid);
      $this->db->update('starmodel', $udata);
    }
    else
    {
      echo $this->upload->display_errors();
    }
  }
}

【问题讨论】:

    标签: codeigniter codeigniter-2


    【解决方案1】:

    name参数必须是userfile

    根据to the CI File Uploading Documentation

    默认情况下,上传例程期望文件来自表单 名为 userfile 的字段,并且表单必须是“多部分”类型:

    <form method="post" action="some_action" enctype="multipart/form-data" />
        <input type="file" name="userfile" size="20" />
        <input type="submit" value="upload" />
    </form>
    

    话虽如此,我认为 CI 的库目前不支持 HTML5 的 multiple 文件上传。对于自定义库,您应该 peak around CI's forums

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-10
      • 2012-01-12
      • 2013-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多