我正在尝试在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();
}
}
}
答案 0 :(得分:0)
name参数必须是 userfile
根据to the CI File Uploading Documentation:
默认情况下,上传例程期望文件来自表单 字段名为userfile,表单必须是“multipart”类型:
<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的多个文件上传。您应该peak around CI's forums了解自定义库。