user
user

Reputation: 213

image upload in codeigniter

I am trying to upload the image in the following code: Controller:

public function do_register()
    {
        $this->load->library('form_validation');

        $this->form_validation->set_rules('uname', 'Username', 'required|min_length[4]|max_length[15]');
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
        $this->form_validation->set_rules('pass', 'Password', 'required|min_length[4]');
        $this->form_validation->set_rules('address', 'Details', 'required|min_length[4]');
        if($this->form_validation->run() == FALSE)
        {
            $this->load->view('login_view');
        }
        else
        {
            $path = $_FILES['image']['name'];
            $imgext=strtolower(strrchr($path,'.'));
            $imgname= $this->generateRandomString().$imgext;
            if($path!='')
            {
                $im= $this->config->item('base_url').'/uploads'.'/'.$imgname;
                $x=$this->do_upload($imgname);
                $data['img']=$im;
            }

            $this->search_model->register_user($data['img']);
            $this->load->view('register_view'); 
        }
    }   
    function generateRandomString()
    {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
        $randomString = '';
        for ($i = 0; $i < 8; $i++) {
            $randomString .= $characters[rand(0, strlen($characters) - 1)];
        }
        return $randomString;
    }   
    function do_upload($img)
    {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';

        $config['max_size'] = '1024 ';

        $config['file_name'] = $img;
        $this->load->library('upload',$config);

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

        {
            $error = array('error' => $this->upload->display_errors()); 
            print_r($error);
             die();
            register("search/register");
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view(register_view,$data);
            return $data;
        }
        return;
    }

i upload the image size greater than 1 mb, do registration then i did not get the error messsage . But when i print the error using the code print_r($error) ,

error message is displayed as "The uploaded file exceeds the maximum allowed size in your PHP configuration file."

How to solve this issue?

Upvotes: 2

Views: 300

Answers (1)

Saty
Saty

Reputation: 22532

Sounds like you need to increase post_max_size in php.ini. also increased upload_max_filesize

in php.ini

Set

post_max_size = 256M// according to your requirment
upload_max_filesize 128M

Upvotes: 3

Related Questions