致命错误:调用未定义的方法Upload :: do_upload()

时间:2016-05-09 08:57:35

标签: file-upload methods fatal-error codeigniter-3

尝试上传文件时出现此错误。

这是我的代码


class Upload extends CI_Controller {

    function __construct() {
        parent::__construct();

        $this->load->model(array(
                                  'm_campaign' 
                                  ,'m_upload'
                                )
                            );

        $this->load->helper(array(
                                   'form' 
                                   ,'url'
                                )
                            );

    }

    public function index()
    {
        $data = array(
                        'select_campaign'   => $this->select_campaign(),
                        'view'              => 'upload',
                        'js'                => 'script_upload'
                    );

        $this->load->view('admin/template', $data);
    }

    function select_campaign(){
        $select_campaign = $this->m_upload->table_campaign();
        return $select_campaign;
    }

    function start_upload(){

        if (!empty($_FILES)) {
            $config = array(
                                'allowed_types' => 'jpg|xls|xlsx' 
                                ,'upload_path'  =>  base_url('assets/media/excel/')
                                ,'max_size'     =>  1000000
                                ,'max_width'    =>  4024
                                ,'max_height'   =>  1768
                                ,'overwrite'    =>  true
                            );
            $this->load->library('upload', $config);

            $this->upload->do_upload();
        }
        redirect('admin/upload');
    } }
}

我试图搜索但仍然混淆。

谢谢大家在这里

1 个答案:

答案 0 :(得分:0)

可能是因为您的配置参数没有初始化。

之后试试
$this->load->library('upload', $config);
    $this->upload->initialize($config);