title: Validate if a file is selected for upload in codeigniter
body: <p>Hi I'm having some trouble about the upload file part. Well basically I have a form with upload logo part wherein if a user doesn't select a logo he/she can still update his/her profile at the same time the user can also choose to upload a logo but it has some limitations. Now I don't know how I can validate that part to know if he/she chooses an image or not. Here's my code so far in CI controller:</p>
  
  <pre><code>if (//CHECK IF THERE IS A FILE FOR UPLOAD){
                  $new_name = $data['id'];
  
                  $config['upload_path'] = './Logos/';
                  $config['allowed_types'] = 'jpg|png|gif';
                  $config['max_size'] = '100';
                  $config['max_width']  = '100';
                  $config['max_height']  = '100';
  
                  $this-&gt;load-&gt;library('upload', $config);
  
                      if ( ! $this-&gt;upload-&gt;do_upload())
                      {
                          array_push($data['error_message'], "You have the following errors in your entry:\n");
                          array_push($data['error_message'], "- Logo must be 100x100 pixels in size not exceeding 100KB with JPG,PNG or GIF format");
                          array_push($data['error_message'], "\nLogo upload failed.");
                          $data['check_error'] = true;
                      }
                      else
                      {
                          $data = array('upload_data' =&gt; $this-&gt;upload-&gt;data());
  
                          //DO UPDATE PART HERE
                          $file = $data['upload_data']['file_name'];
                          rename($config['upload_path'] . $file, $config['upload_path'] .$new_name.'.jpg');
                          //GO TO SETTINGS
                          $this-&gt;load-&gt;helper('url');  
                          redirect($data['base'].'settings');
                      }
                  }
  </code></pre>
  
  <p>The part in if is where I wanted to set a validations. I tried some tricks but all of those doesn't work properly.</p>
  
  <p>Here's my view part where if the logo of the certain ID already exists it's just display his/her logo or else displays the default logo:</p>
  
  <pre><code> &lt;tr&gt;
      &lt;td&gt;&lt;p class="titles"&gt;Logo&lt;/p&gt;&lt;/td&gt;
      &lt;td&gt;
      &lt;div&gt;
          &lt;input type="text" id="fileName" class="file_input_textbox" readonly="readonly"&gt;
  
          &lt;div class="file_input_div"&gt;
            &lt;input type="button" value="Browse" class="file_input_button" /&gt;
            &lt;input type="file" class="file_input_hidden" onchange="javascript: document.getElementById('fileName').value = this.value" id="upload" name="userfile" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;p class="titles"&gt;100px x 100px jpg, png or gif only.&lt;/p&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;&lt;p class="titles"&gt;Current Logo&lt;/p&gt;&lt;/td&gt;
  &lt;td&gt;
      &lt;img src="&lt;?php if(is_array(@getimagesize($base."Logos/".$id.".jpg"))){echo $base."Logos/".$id.".jpg";}else{echo $base."Logos/default.jpg";} ?&gt;"  style="margin:0px 0px 0px 90px;"/&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>