'codeigniter not showing file upload error

I am using CodeIgniter file uploading class to upload a image. But if I try and select a pdf instead of image I do not get any errors on form submission.

relevant code

$config = array(
    'allowed_types' => 'jpg|jpeg|gif|png',
    'upload_path'   => $this->article_path.'/magazine',
    'max_size'      => 2000
);

$this->load->library('upload', $config);
$this->upload->do_upload();
$this->upload->display_errors();
$image_data = $this->upload->data();


Solution 1:[1]

It is because you never went to the documentation (here), please do so in order to perform better in CodeIgniter framework.


this should give you heads up (please read comments)

$config = array(
    'allowed_types' => 'jpg|jpeg|gif|png',
    'upload_path'   => $this->article_path.'/magazine',
    'max_size'      => 2000
);

$this->load->library('upload', $config);

if ( ! $this->upload->do_upload()) //important!
{
    // something went really wrong show error page
    $error = array('error' => $this->upload->display_errors()); //associate view variable $error with upload errors

    $this->load->view('upload_form', $error); //show error page
}
else
{
    //all is good we upload
    $data = array('upload_data' => $this->upload->data()); 

    $this->load->view('upload_success', $data);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1