Search code examples
phpcodeignitercodeigniter-3

error in file uploading codeIgniter


Below is the code for my controller....

public function do_upload()
    {

        $config['upload_path']='./upload/';
        $config['allowed_types']='gif|jpg|png';
        $this->load->library('upload',$config);
        $this->upload->do_upload('image_file');
        if($this->upload->do_upload('image_file'))
        {
            $filedata = $this->upload->data();
            $filename = $filedata['raw_name'].$filedata['file_ext'];

            return $filename;
        }

    }

After this call this function where You want to make this upload...in controller

    if($_FILES)
                    {
                        $this->do_upload();
                    }

but file is not uploaded.......why?


Solution

  • Hope this will help you :

    Your do_upload method should be like this :

    public function do_upload() 
    {
        $config['upload_path'] = './upload/';
        $config['allowed_types']='gif|jpg|png';
        $this->load->library('upload', $config);
        if($this->upload->do_upload('image_file'))
        {
            $filename = $this->upload->data('file_name');
            echo  $filename;die;
        }
        else
        {
            print_r($this->upload->display_errors());
            die;
        }
    }
    

    UPDATE :

    set upload_max_filesize in your php ini greater than 2MB,

    if it is wamp just follow :

    click on wamp => php => php settings => upload_max_filesize