title: How to restrict image size to a specific size when uploading in Codeigniter?
body: <p>My controller function is</p>
  
  <pre><code>public function add() { 
      $blog_title  = $this-&gt;input-&gt;post("qes_blog_title"); 
      $description = htmlentities($_POST['qes_blog_description']); 
      $edit_status = $this-&gt;input-&gt;post("edit"); 
      $filename    = $blog_title . date('ymdhis'); 
      if ($this-&gt;session-&gt;userdata('user_type') == "SA") { 
          $dirname  = (dirname(dirname(dirname(__FILE__)))) . 
              '/uploads/blog/admin'; 
          $usertype = "1"; 
      } else { 
          $dirname  = (dirname(dirname(dirname(__FILE__)))) . '/uploads/blog/' 
              . $this-&gt;session-&gt;userdata('user_id'); 
          $usertype = "0"; 
      } 
      if (!file_exists($dirname)) { 
          mkdir($dirname, 0777, true); 
      } 
      $config['upload_path']   = $dirname; 
      $config['file_name']     = $filename; 
      $config['allowed_types'] = 'jpeg|jpg|png'; 
      $this-&gt;load-&gt;library('upload', $config); 
      $this-&gt;upload-&gt;initialize($config); 
      if (!$this-&gt;upload-&gt;do_upload("qes_blog_image")) { 
          //print_r($this-&gt;upload-&gt;display_errors()); 
          $data = array( 
              'qes_blog_title' =&gt; $blog_title, 
              'qes_blog_description' =&gt; $description, 
              'qes_vendor_id' =&gt; $this-&gt;session-&gt;userdata('user_id'), 
              'qes_user_type' =&gt; $usertype, 
              'qes_created_at' =&gt; date('Y-m-d H:i:s') 
          ); 
      } else { 
          if ($edit_status) { 
              $condition       = array( 
                  'qes_vendor_blog_id' =&gt; $edit_status 
              ); 
              $categoryDetails = $this-&gt;common_model-&gt;get_row($condition, $this-&gt;tablename); 
              if ($categoryDetails-&gt;qes_category_image != NULL) { 
                  if ($this-&gt;session-&gt;userdata('user_type') == "SA") { 
                      unlink((dirname(dirname(dirname(__FILE__)))) . '/uploads/blog/admin/' . $categoryDetails-&gt;qes_blog_image); 
                  } else { 
                      unlink((dirname(dirname(dirname(__FILE__)))) . '/uploads/blog/' . $categoryDetails-&gt;qes_vendor_id . "/" . $categoryDetails-&gt;qes_blog_image); 
                  } 
              } 
          } 
          $uploqes_data     = $this-&gt;upload-&gt;data(); 
          $uploqes_filename = $uploqes_data['file_name']; 
          $data             = array( 
              'qes_blog_title' =&gt; $blog_title, 
              'qes_blog_description' =&gt; $description, 
              'qes_vendor_id' =&gt; $this-&gt;session-&gt;userdata('user_id'), 
              'qes_user_type' =&gt; $usertype, 
              'qes_blog_image' =&gt; $uploqes_filename, 
              'qes_created_at' =&gt; date('Y-m-d H:i:s') 
          ); 
      } 
      $condition    = array( 
          'qes_blog_title' =&gt; $blog_title 
      ); 
      $blog_details = $this-&gt;common_model-&gt;get_row($condition, $this-&gt;tablename); 
      if ($edit_status) { 
          if (count($blog_details) &gt; 0) { 
              if ($blog_details-&gt;qes_blog_title == $blog_title) { 
                  $condition = array( 
                      'qes_vendor_blog_id' =&gt; $edit_status 
                  ); 
                  $result    = $this-&gt;common_model-&gt;update_row($data, $condition, $this-&gt;tablename); 
                  $status    = 'Blog "&lt;b&gt;' . $blog_title . '&lt;/b&gt;" Successfully Updated'; 
              } else { 
                  $htm    = "0"; 
                  $result = "0"; 
                  $status = "0"; 
              } 
          } else { 
              $condition = array( 
                  'qes_vendor_blog_id' =&gt; $edit_status 
              ); 
              $result    = $this-&gt;common_model-&gt;update_row($data, $condition, $this-&gt;tablename); 
              $status    = 'Blog "&lt;b&gt;' . $blog_title . '&lt;/b&gt;" Successfully Updated'; 
          } 
      } else { 
          if (count($blog_details) &gt; 0) { 
              if ($blog_details-&gt;qes_blog_title == $blog_title) { 
                  $htm    = "0"; 
                  $result = "0"; 
                  $status = "0"; 
              } else { 
                  $result = $this-&gt;common_model-&gt;insert_data($this-&gt;tablename, $data); 
                  $status = 'Blog "&lt;b&gt;' . $blog_title . '&lt;/b&gt;" Successfully Created'; 
              } 
          } else { 
              $result = $this-&gt;common_model-&gt;insert_data($this-&gt;tablename, $data); 
              $status = 'Blog "&lt;b&gt;' . $blog_title . '&lt;/b&gt;" Successfully Created'; 
          } 
      } 
      if ($result) { 
          $htm = $result; 
          $this-&gt;session-&gt;set_flashdata('success_msg', $status); 
      } else { 
          $htm = '0'; 
          $this-&gt;session-&gt;set_flashdata('success_msg', 'Error While Creating Parent'); 
      } 
      echo $htm; 
  }
  </code></pre>
  
  <p>I'm a beginner in Codeigniter.</p>
  
  <p>How to restrict the size of image while uploading. Only images of specific size can be uploaded. The above is the controller function to add blog. How to specify the size in the above code. How to keep a condition like "upload image only of the specified size" while uploading image in Codeigniter?</p>