title: Form validation With File Upload
body: <p>i am having a form with a file upload.</p>
  
  <p>i need to validate the form</p>
  
  <p>here's my validation code</p>
  
  <pre><code>   $this-&gt;form_validation-&gt;set_rules('career_experience','Experience','trim|required|xss_clean');
     $this-&gt;form_validation-&gt;set_rules('career_salary','Salary','trim|required|xss_clean');
     $this-&gt;form_validation-&gt;set_rules('career_resume','Resume','callback_check_file');
  
  function check_file($str)
  {
     if($str=="")
          {
               $this-&gt;form_validation-&gt;set_message('check_file', 'Please Upload A Resume');
               return false;
          }
          else if($str!="")
          {
               $ext = array();
               $ext = explode(".",$str);
               $allowed_ext = array("doc","pdf","pdf","docx","txt");
               if(isset($ext[1]) &amp;&amp; $ext[1]!="")
                  {
                      if (in_array($ext[1], $allowed_ext)) 
                      {
                          return true;
                      }
                      else
                      {
                          $this-&gt;form_validation-&gt;set_message('check_file', 'The File Is Not Supported');
                          return false;
                      }
                  }
          }
  
  }
  </code></pre>
  
  <p>Now the issue is that the validation message for career_resume always gives me </p>
  
  <pre><code>"Please upload a resume";
  </code></pre>
  
  <p>so it means even if i am selecting a file, its stating $str as empty string or "" string;</p>
  
  <p>Why is that so??</p>
  
  <p>Doesn't it take <code>$str = $_FILES['name'];</code></p>
  
  <p>Now career resume is the input="file"</p>
  
  <p>here's the form</p>
  
  <pre><code>&lt;form name="career_form" id="career_form" method="post"
              enctype="multipart/form-data" action="&lt;?php echo site_url('pages/send_career_mail');?&gt;"&gt;
  &lt;input name="career_experience" type="text"/&gt;
  &lt;input name="career_salary" type="text"/&gt;
  &lt;input name="career_resume" type="file"/&gt;
  &lt;/form&gt;
  </code></pre>