title: Codeigniter Image Upload On Registration Form
body: <p>Hi guys I am new to Codeigniter and new to the MVC webdesign, and I've been trying to implement this image upload into my registration form with no success. </p>
  
  <p>In another page where the user edits his profile i've added it successfully but for the life of me i can't add it to this register form. It's not uploading to my database or to my server </p>
  
  <p>Here is what I've tried:</p>
  
  <pre><code>//upload controller
  public function do_upload() {
       $user = $this-&gt;ion_auth-&gt;user()-&gt;row();
       $config['upload_path']   = './some/folder/'; 
       $config['allowed_types'] = 'jpg|png'; 
       $config['max_size']      = 2000; 
       $config['overwrite'] = TRUE;
       $current_user_id = $user-&gt;id;
       $current_user_username = $user-&gt;username;
       $config['file_name'] = $current_user_id . "_" . $current_user_username;
       //$config['max_width']     = 1024; 
       //$config['max_height']    = 768;  
       $this-&gt;load-&gt;library('upload', $config);
  
       if ( ! $this-&gt;upload-&gt;do_upload('userfile')) {
          $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors());
          redirect('/', 'refresh');   
       }
       else { 
              $vars['user'] = $user;
              $current_user = $user-&gt;id;      
              $vars['recent_messages'] = $this-&gt;ss_messages_model-&gt;find_all_array(array('id_user' =&gt; $user-&gt;id), 'date_added desc', 5);
              $image_data = $this-&gt;upload-&gt;data();
              $data = array('userfile' =&gt; $image_data['file_name']);
              $this-&gt;ion_auth-&gt;update($user-&gt;id, $data);
  
       }
    }
  
  //register function in the auth controller 
  function register()
      {
          $this-&gt;data['title'] = "Register User";
          $this-&gt;data['lang'] = $this-&gt;clang;
          **$this-&gt;do_upload();**
          $tables = $this-&gt;config-&gt;item('tables','ion_auth');
  
          //validate form input
          $this-&gt;form_validation-&gt;set_rules('first_name', $this-&gt;lang-&gt;line('register_fname'), 'alpha_space|required|xss_clean'); 
          $this-&gt;form_validation-&gt;set_rules('last_name', $this-&gt;lang-&gt;line('register_user_validation_lname_label'), 'alpha_space|required|xss_clean');
  
          if ($this-&gt;form_validation-&gt;run() == true)
          {
              $username = strtolower($this-&gt;input-&gt;post('first_name')) . ' ' . strtolower($this-&gt;input-&gt;post('last_name'));
              $email    = strtolower($this-&gt;input-&gt;post('email'));
              $password = $this-&gt;input-&gt;post('password');
  
              $additional_data = array(
              'first_name' =&gt; $this-&gt;input-&gt;post('first_name'),
              'last_name'  =&gt; $this-&gt;input-&gt;post('last_name'),
              **'userfile'      =&gt; $this-&gt;input-&gt;post('userfile');**
              );
          }
          if ($this-&gt;form_validation-&gt;run() == true &amp;&amp; $this-&gt;ion_auth-&gt;register($username, $password, $email, $additional_data))
          {
              //check to see if we are creating the user
              //redirect them back to the admin page
              $this-&gt;session-&gt;set_flashdata('message', $this-&gt;ion_auth-&gt;messages());
              $this-&gt;_render_page("auth/_success");
          }
          else
          {
              //display the register user form
              //set the flash data error message if there is one
              $this-&gt;data['message'] = (validation_errors() ? validation_errors() : ($this-&gt;ion_auth-&gt;errors() ? $this-&gt;ion_auth-&gt;errors() : $this-&gt;session-&gt;flashdata('message')));
  
              $this-&gt;data['image']= $this-&gt;_create_captcha();
  
              $this-&gt;_render_page('auth/register', $this-&gt;data);
          }
      }
  
  **//view**
  &lt;div class="input-box"&gt;
              &lt;div class="agent-lable"&gt;&lt;?php echo "Picture: (jpg or png)"; ?&gt;
              &lt;/div&gt;&lt;br&gt;
              &lt;input type = "file" name = "userfile" size = "20" /&gt;
      &lt;/div&gt;
  </code></pre>