0

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();

1 Answer 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);
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks Kyslik. But in hurry i always tend to miss the importance of documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.