有人可以帮助我从单个表单上传多个文件。如果可能请举个例子。我通过互联网经历了几个地方,但没有找到任何解决方案。下面是我的上传功能模型中的代码,它适用于单个上传,但不适用于单个表单的多个上传。
function upload(){
$config[$a]=array(
'allowed_types'=>'xlsx',
'upload_path'=> $this->gallery_path,
'overwrite'=>true,
'max_size'=>2000,
);
$this->load->library('upload',$config);
$this->upload->do_upload();
}
提前致谢。
答案 0 :(得分:0)
试试这个:
function do_upload()
{
foreach ($_FILES as $index => $value)
{
if ($value['name'] != '')
{
$this->load->library('upload');
$this->upload->initialize($this->set_upload_options());
//upload the image
if ( ! $this->upload->do_upload($index))
{
$error['upload_error'] = $this->upload->display_errors("<span class='error'>", "</span>");
//load the view and the layout
$this->load->view('pages/uploadform', $error);
return FALSE;
}
else
{
$data[$key] = array('upload_data' => $this->upload->data());
$this->load->view('pages/uploadsuccess', $data[$key]);
}
}
}
}
//here put your rules
private function set_upload_options()
{
//upload an image options
$config = array();
$config['upload_path'] = FCPATH.'public/uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['encrypt_name'] = TRUE;
$config['max_width'] = '2000';
$config['max_height'] = '1500';
$config['max_size'] = '2048';
return $config;
}