title: Codeigniter validating file upload and text input in one form
body: <p>I have a form with text inputs and a file input. What is a proper way validate both input types using Codeigniter's validation library? I found some solutions but they don't work properly or seem like an overkill (creating new libraries or modifying CI system files). </p>
  
  <p>In my view I'm using 1 multipart form and displaying both text validation error and upload errors. </p>
  
  <p>Here is what I have so far in my Controller...</p>
  
  <pre><code>function create() //create new post
  {           
      $this-&gt;form_validation-&gt;set_rules('content', 'Entry', 'trim|required|xss_clean');
      $this-&gt;form_validation-&gt;set_rules('category_id', 'Category', 'trim|required|xss_clean|integer'); 
  
      //Text input fields
      if ($this-&gt;form_validation-&gt;run() == FALSE)
      {
          $this-&gt;load-&gt;view('new_post');
      }       
      else
      {
              $config['upload_path'] = './uploads/posts/';
              $config['allowed_types'] = 'jpg|png';               
              $config['max_size'] = '800'; //in KB
  
              $this-&gt;load-&gt;library('upload', $config);
  
              //File Upload
              if (! $this-&gt;upload-&gt;do_upload())
              {
                  $upload_error['upload_error'] = array('error' =&gt; $this-&gt;upload-&gt;display_errors()); 
  
                  $this-&gt;load-&gt;view('my_view', $upload_error);
  
                  return FALSE;
              }
  
               //Add to database 
               $data = array (
                 'user_id' =&gt; $this-&gt;tank_auth-&gt;get_user_id(),
                 'category_id' =&gt; $this-&gt;input-&gt;post('category_id'),
                 'content' =&gt; $this-&gt;input-&gt;post('content')
               );
  
               $this-&gt;Posts_model-&gt;create_post($data);
  
               $this-&gt;session-&gt;set_flashdata('success', 'Post_added!');
               redirect('posts');
      }       
  
  }
  </code></pre>
  
  <p>I keep getting <code>You did not select a file to upload.</code> in my view.</p>