title: undefined variable $error in file uploading class codeingiter
body: <p>I am trying to use Codeigniter upload class to upload pdfs to a folder which is working fine.However, the error variable is showing as undefined and because of this I could not see the error if iam uploading a wrong file. Please suggest.</p>
  
  <p>Here is my view ,</p>
  
  <pre><code>             &lt;?php echo $error;?&gt;
  
               &lt;?php echo form_open_multipart('admin/admin_elements/do_upload_pdf');?&gt;
  
               &lt;input type="file" name="pdf" class="btn" /&gt;
  
               &lt;br /&gt;&lt;br /&gt;
  
               &lt;input type="submit"  class="btn btn-info" value="upload" /&gt;
  
               &lt;?php echo form_close(); ?&gt;
  </code></pre>
  
  <p>and my controller functions,</p>
  
  <pre><code>      function add_pdf(){
  
                    $data['main_content'] ='admin/elements/add_pdf';
                    $this-&gt;load-&gt;view('includes/template', $data);          
  
        }
  
        function do_upload_pdf(){
  
                    $config['upload_path'] = './uploads/';
                    $config['allowed_types'] = 'pdf';
                    $config['max_size'] = '10000';
  
                    $this-&gt;load-&gt;library('upload', $config);
  
                    if ( ! $this-&gt;upload-&gt;do_upload('pdf'))
                    {
                       $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors());
  
                       $data['main_content'] ='admin/elements/add_pdf';
                       $this-&gt;load-&gt;view('includes/template', $data);
  
                    }
                    else
                    {
                       $chapter_id=$this-&gt;session-&gt;userdata('chapter_id');
                       redirect("/admin/elements/".$chapter_id);
                   }
  }
  </code></pre>
  
  <p>Thanks.</p>