2013-04-09 64 views
1

有人可以帮助我从单个表单上传多个文件。如果可能的话请举一些例子。我通过互联网浏览过几个地方,但没有找到任何解决方案。下面是我的代码模型中的上传功能,它适用于单一上传,但不适用于从单一表单进行多次上传。如何从codeigniter中的单个表单上载多个文件

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

什么是'$配置[$一]''$了'? – 2013-04-09 21:24:42

+0

对不起,我的坏。忽略$ config [$ a],它将是$ config – leon24 2013-04-10 06:49:37

回答

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; 
} 
相关问题