Fatal error: Call to undefined method CI_Upload

8.3k views Asked by At

I am already using codeigniter uploading class somewhere else with no issues to upload pdf files. Now, I am trying to implement a basic image uploader. This is my controller's code:

class Upload_image extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->model('queries_model');
        $this->load->helper(array('form', 'url'));
        $this->load->library(array('form_validation', 'session', 'common'));
    }

    function index()
    {
        if ($this->session->userdata('logged_in'))
        {
            $id            = $this->input->get('id');
            $is_image      = $this->input->get('is_image');
            $data['title'] = ucfirst('Subir imagen');
            $pck_info      = $this->queries_model->get_excursion_by_id($id, 1);

            $this->load->view('admin/common/header', $data);
            $this->load->view('admin/upload_image', array('error' => ' ', 'pck_name' => $pck_info[0]->title, 'is_image' => $is_image));
            $this->load->view('admin/common/footer');
        }
        else
        {
            redirect('admin/login', 'refresh');
        }
    }

    function do_image_upload()
    {
        $config['upload_path']   = './assets/img/most-popular';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']      = '100';
        $config['max_width']     = '1024';
        $config['max_height']    = '768';
        $config['overwrite']     = true;

        $this->load->library('upload', $config);

        if ( ! $this->upload->do_image_upload())
        {
            $error         = array('error' => $this->upload->display_errors('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>', '</div>'));
            $data['title'] = ucfirst('Subir información');

            $this->load->view('admin/common/header', $data);
            $this->load->view('admin/upload_image', $error);
            $this->load->view('admin/common/footer');
        }
        else
        {
            $this->load->view('admin/common/header', $data);
            $this->load->view('admin/common/upload_success');
            $this->load->view('admin/common/footer');
        }
    }
}

This is what I get

( ! ) Fatal error: Call to undefined method CI_Upload::do_image_upload() in C:\wamp\www\aguasprofundas\application\controllers\admin\upload_image.php on line 43
Call Stack
#   Time    Memory  Function    Location
1   0.0000  148816  {main}( )   ..\index.php:0
2   0.0020  184888  require_once( 'C:\wamp\www\aguasprofundas\system\core\CodeIgniter.php' )    ..\index.php:202
3   0.0320  1717016 call_user_func_array:{C:\wamp\www\aguasprofundas\system\core\CodeIgniter.php:359} ( )   ..\CodeIgniter.php:359
4   0.0320  1717208 Upload_image->do_image_upload( )    ..\CodeIgniter.php:359

I been reading some posts about case sensitive, but I do not think this is the case. Any help will be more than welcome.

Thanks!

1

There are 1 answers

3
Wing Lian On BEST ANSWER

if ( ! $this->upload->do_image_upload())

should be

if ( ! $this->upload->do_upload())