Valor_
Valor_

Reputation: 3591

CodeIgniter upload fails - filetype is not allowed

I'm keep getting error The filetype you are attempting to upload is not allowed, when I try to upload MP4 movie file.

This is my upload function

public function upload_post() {
        $config['upload_path'] = ROOT_DIR . $dataBasePath;
        $config['allowed_types'] = 'avi|mov|mp4|jpeg|jpg|png';
        $config['remove_spaces'] = true;
        $config['max_size'] = '80000';
        $config['encrypt_name'] = true;
        $this->upload->initialize($config);
        if ($this->upload->do_upload('userFile')) {
            $uploadData = $this->upload->data();
            if ($uploadData) {
                $this->response([
                   'data' => $uploadData
                ], REST_Controller::HTTP_OK);
            } else {
                $this->response([
                    'status' => false,
                    'message' => 'failed'
                ], REST_Controller::HTTP_CONFLICT);
            }
        } else {
            var_dump($_FILES);
            die();
            $this->response([
                'status' => false,
                'errors' => ['error' => $this->upload->display_errors()]
            ], REST_Controller::HTTP_CONFLICT);
        }
}

When I upload a file and var_dump($_FILES) data if upload fails, this is the result

array (size=1)
  'userFile' => 
    array (size=5)
      'name' => string '1-video.mp4' (length=11)
      'type' => string '' (length=0)
      'tmp_name' => string '' (length=0)
      'error' => int 1
      'size' => int 0

The result of var_dump(get_mime_by_extension($_FILES['userFile']['name'])) is following

'video/mp4'

I have also checked my mimes.php file and I have entire

'mp4'   =>  array('video/mp4', 'application/octet-stream'),

I don't know what else should I do or check in order to upload a file successfully? Uploading images works OK. If you need any additional informations, please let me know and I will provide. Thank you

Upvotes: 0

Views: 462

Answers (3)

user8477089
user8477089

Reputation:

This is working in my code Perfectly and uploaded file move to my folder.

controller

public function addd(){

   $images = "property.".pathinfo($_FILES['images']['name'], 
       PATHINFO_EXTENSION);

   $addimg = array(
            "images" =>  $images,
        );

    $this->db->insert("tbl_name",$addimg);

    $uploadPath = "./html/images/property";

    $config['upload_path'] = $uploadPath;
    $config['allowed_types'] = 'gif|jpg|png|pdf|mp4';
    $config['overwrite'] = TRUE;
    $config['encrypt_name'] = FALSE;
    $config['remove_spaces'] = TRUE;

    $config['file_name'] = "property";
    $this->load->library('upload', $config);
    $this->upload->do_upload('images');
    $this->upload->display_errors();
}

Upvotes: 1

Rudra
Rudra

Reputation: 555

Change mp4 to MP4

$config['allowed_types'] = 'MP4'

Upvotes: 0

Sachin Aghera
Sachin Aghera

Reputation: 506

added both in array in the mime type list in my config folder:

'mp4' => array('video/mp4', 'application/octet-stream'),

Upvotes: 1

Related Questions