1

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

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

}

提前致谢。

4

1 回答 1

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;
}
于 2013-04-09T16:31:10.527 回答