Welcome Guest, Not a member yet? Register   Sign In
Ion-Auth application bug: undefined index userfile
#1

I am working on a Users application with Codeigniter 3, Ion-Auth and Bootstrap 4.

I have tried to add an avatar at user's registration.


For this purpose, I first added an "avatar" column to the users 
table. Then, in the view I added:


Code:
<div class="form-group">
    <?php $avatar['class'] = 'form-control';
    echo lang('edit_user_avatar_label', 'avatar');?>
    <input type="file" class="form-control" name="userfile" id="avatar" size="20">
</div>

In the [b]Auth[/b] controller (application/controllers/Auth.php)
 I created this upload method:
Code:
public function upload_image() {
    $config['upload_path'] = './assets/img/avatars';
    $config['allowed_types'] = 'jpg|jpeg|png';
    $config['max_size'] = 2048;

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

    if (!$this->upload->do_upload('userfile')) {
        $error = array('error' => $this->upload->display_errors());
        $this->_render_page('auth' . DIRECTORY_SEPARATOR . 'create_user', $error);

    } else {
        $this->$data = array('image_metadata' => $this->upload->data());
        $this->_render_page('auth' . DIRECTORY_SEPARATOR . 'create_user', $this->$data);
    }
}

Finally, to the existing $additional_data 
array, from the original create_user() method, I added the line  'avatar' => $_FILES['userfile']['name']:
Code:
$additional_data = [
    'first_name' => $this->input->post('first_name'),
    'last_name' => $this->input->post('last_name'),
    'avatar' => $_FILES['userfile']['name'],
    'company' => $this->input->post('company'),
    'phone' => $this->input->post('phone'),
];

The above line, when added to the $data 
array from the edit_user($id)method, has no errors, yet when added to the $additional_data array, it gives the error: 
Code:
Undefined index: userfile

Where is my mistake?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB