title: how to validate image from form validation library codeigniter
body: <p>I am trying to validate an image from my form validation's extended class in codeigniter but it is not working</p>
  
  <p>controller </p>
  
  <pre><code>public function __construct() {
      parent::__construct();
      $this-&gt;load-&gt;library('form_validation');
  }
  
  public function add_photo() { 
  
   $this-&gt;form_validation-&gt;set_rules('pic','Photo','validate_image['.$_FILES['pic'].']');
  
  
    if($this-&gt;form_validation-&gt;run()) {
     //some further coding
    }
  }
  </code></pre>
  
  <p>in my library </p>
  
  <pre><code>class MY_Form_validation extends CI_Form_validation {
  
          public function __construct() {
          parent::__construct();
          $this-&gt;_CI = &amp;get_instance();
      }
  
  public function validate_image($image = NULL) {
          print_r($image);
          $file_name      =   $image['name'];
  
          $allowed_ext    =   array('jpg', 'jpeg', 'png', 'gif', 'bmp');
          $ext                =   strtolower(end(explode('.', $file_name)));
  
          $allowed_file_types =   array('image/jpeg','image/jpg','image/gif','image/png');
          $file_type              =   $image['type'];
  
          if(!in_array($ext, $allowed_ext) &amp;&amp; !in_array($file_type, $allowed_file_types)) {
              $this-&gt;_CI-&gt;form_validation-&gt;set_message('validate_image', 'This file type is not allowed');
              return false;
          }
  
          if($image['size'] &gt; 2097152) {
              $this-&gt;_CI-&gt;form_validation-&gt;set_message('validate_image', 'File size Exeeds');
              return false;
          } else {
              return true;
          }
      }
  
  
  }
  </code></pre>
  
  <p>any suggestion and help will be appriciated thanks.</p>