0

I am trying to implement CodeIgniter's upload library. But everytime I tried to upload, it keeps on saying that I haven't selected a file to upload.

Here is the code:

View:

<form action="<?= base_url().'principal/updateuniform' ?>" method="post">
                    <h3 style="text-align:center">Polo</h3>
                    <input type="hidden" name="imageid" value="<?= $img_id ?>">
                    <input type="hidden" name="imagename" value="<?= $img_name ?>">
                    <input type="file" name="imagefile" accept="image/*" /><br>
                    <button type="submit" class="btn btn-gold"><span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Upload</button>
                </form> 

Upload function:

function updateuniform(){
        $img_id = $this->input->post('imageid');
        $img_name = $this->input->post('imagename');

        $config['upload_path']          = './images/';
        $config['allowed_types']        = 'gif|jpg|png';
        $config['max_size']             = 5000;
        $config['max_width']            = 3000;
        $config['max_height']           = 4000;
        $config['overwrite']            = TRUE;
        $config['file_name']            = $img_name;

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

        $img = $this->input->post('imagefile');;

        $id = $this->session->userdata('id');
        $user['user'] = $this->UsersModel->select_principal($id);

        if (!$this->upload->do_upload($img)){
            $data['error'] = $this->upload->display_errors();
            $data['uniforms'] = $this->InfoModel->getUniforms();

            $this->load->view('include/header_principal',$user);
            $this->load->view('principal/manage_uniforms', $data);
            $this->load->view('include/footer_principal');
        } else {
            $img_path = 'images/'.$this->upload->data('orig_name');
            $data['success'] = 'Uniforms has been updated.';

            $this->InfoModel->updateUniform($img_path);

            $this->load->view('include/header_principal',$user);
            $this->load->view('principal/manage_uniforms', $data);
            $this->load->view('include/footer_principal');
        }

    }

I also tried to echo the $img and it's displaying the file name.

2 Answers 2

1
$this->upload->do_upload($img)

The param should be the filedname,like:

$this->upload->do_upload('imagefile')
Sign up to request clarification or add additional context in comments.

Comments

0

Add enctype="multipart/form-data" in your form tag of view this allows you to get $_FILE value and This will solve your issue I guess

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.