Error when uploading multiple files in Codeigniter

被刻印的时光 ゝ 提交于 2019-12-11 23:48:20

问题


I am trying to use multiple file upload in CodeIgniter, but I'm getting an error: You did not select a file to upload.

My html code:

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

My php code:

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();
    }
  }
}

回答1:


The name parameter must be userfile

According to the CI File Uploading Documentation:

By default the upload routine expects the file to come from a form field called userfile, and the form must be a "multipart" type:

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

With that said, I do not believe CI's library currently supports HTML5's multiple file uploads. You should peak around CI's forums for custom libraries.



来源:https://stackoverflow.com/questions/9306608/error-when-uploading-multiple-files-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!