1

After updating project files to latest version of Codeigniter now when i upload any file it will return me this Error:

The filetype you are attempting to upload is not allowed.

Code give bellow:

public function test_upload(){
    $config = array(
        'upload_path'   => './assets/upload_test',
        'allowed_types' => 'gif|jpg|png|jpeg|pdf',
        'max_size'      => '2048',
    );
    if($_FILES['file']['name'] != '')
    {
        $image = 'file';
        $upload_data = $this->do_upload($image, $config);
        if($upload_data['condition']=='error')
        {
            echo json_encode(array('condition'=>'error', 'message'=>$upload_data['error'].' (User image)')); exit;
        }else{
            $profile_picture['file'] = $upload_data['upload_data']['file_name'];
        }
    }
    print_r($profile_picture);exit;
}

public function do_upload($image, $config)
{
    $this->load->library('upload');
    $this->upload->initialize($config);
    if ( ! $this->upload->do_upload($image))
    {
        $error = array('condition'=>'error', 'error' => $this->upload->display_errors());
        return $error;
    }
    else
    {
        $data = array('condition'=>'success', 'upload_data' => $this->upload->data());
        return $data;
    }
}

Search a lot but didn't find any good solution. Thanks for everyone response.

Hazrat Bilal
  • 103
  • 1
  • 10

1 Answers1

0

I find my answer from google but i will spend a lot of time. Simply change this line:

'allowed_types' => 'gif|jpg|png|jpeg|pdf'

Replace this line with:

'allowed_types' => '*'

And my issue was resolved.

Hazrat Bilal
  • 103
  • 1
  • 10
  • what type of file you are uploading? '*' accept all type of files, if you give the specific file type it will allow those only – Bergin Oct 15 '18 at 05:26
  • @Bergin i tried to upload PFD and All images format but the solution you suggested is not working for me. Thanks for your response. – Hazrat Bilal Oct 15 '18 at 16:16