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.
Here is my view ,
<?php echo $error;?>
<?php echo form_open_multipart('admin/admin_elements/do_upload_pdf');?>
<input type="file" name="pdf" class="btn" />
<br /><br />
<input type="submit" class="btn btn-info" value="upload" />
<?php echo form_close(); ?>
and my controller functions,
function add_pdf(){
$data['main_content'] ='admin/elements/add_pdf';
$this->load->view('includes/template', $data);
}
function do_upload_pdf(){
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'pdf';
$config['max_size'] = '10000';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('pdf'))
{
$error = array('error' => $this->upload->display_errors());
$data['main_content'] ='admin/elements/add_pdf';
$this->load->view('includes/template', $data);
}
else
{
$chapter_id=$this->session->userdata('chapter_id');
redirect("/admin/elements/".$chapter_id);
}
}
Thanks.