我正在尝试通过codeigniter控制器上传2个文件。当我选择文件并点击提交时,它总是返回error
。但是,当我执行var_dump($_FILES);
时,它会显示文件正在通过但未被codeigniter控制器捕获。
有人能告诉我我做错了什么吗?以下是我的代码
$config['upload_path'] = './docs/';
$config['allowed_types'] = 'jpg|doc|docx';
$config['max_size'] = 10000;
$config['max_width'] = 3000;
$config['max_height'] = 3000;
$this->load->library('upload', $config);
if ( !$this->upload->do_upload('userfile1') || !$this->upload->do_upload('userfile2'))
{
echo "error";
} else {
$f1= $this->upload->data('userfile1');
$f2= $this->upload->data('userfile2');
echo $f1['file_name'];
echo $f2['file_name'];
}
答案 0 :(得分:1)
对于CI中的多个文件上传,请按照以下方式进行 -
$config['upload_path'] = 'uploads/photos/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$this->load->library('upload', $config);
for ($i=0; $i < count($_FILES['photos']['name']); $i++) {
$_FILES['photos[]']['name'] = $_FILES['photos']['name'][$i];
$_FILES['photos[]']['type'] = $_FILES['photos']['type'][$i];
$_FILES['photos[]']['tmp_name'] = $_FILES['photos']['tmp_name'][$i];
$_FILES['photos[]']['error'] = $_FILES['photos']['error'][$i];
$_FILES['photos[]']['size'] = $_FILES['photos']['size'][$i];
if ($this->upload->do_upload('photos[]')) {
$photos_files = array('upload_data' => $this->upload->data());
$photos_arr[] = $photos_files['upload_data']['file_name'];
}else{
$error[] = $this->upload->display_errors();
}
}