Error uploading videos in CodeIgniter

Posted on

Question :

I am not able to upload videos in CodeIgniter, the function works with pdf , but not with other extensions.
The return I have is file type not allowed .


public function add(){
    $dados['tutorial']= $this->uploadArquivo('mp4', 'tutorial');
    $dados['video']= $this->uploadArquivo('mp4', 'video');
    $dados['apostila']= $this->uploadArquivo('pdf', 'apostila');
    $ok= $this->crud->add('roteiro', $dados);
    if ($ok){                           
        echo "<script>alert('Roteiro adicionado com sucesso');</script>";
        echo "<script>alert('Cadastro não efetuado');</script>";

public function uploadArquivo($tipo= NULL, $nome=NULL){
    $config['upload_path'] = 'assets/arquivos/';
    $config['allowed_types'] = $tipo;
    $config['max_size']  = '0';
    $config['max_width']  = '0';
    $config['max_height']  = '0';
    $config['encrypt_name']  = 'true';

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

    if ( !$this->upload->do_upload($nome)){
        $error = array('error' => $this->upload->display_errors());
        echo $nome. " ".$error['error'];
        $arquivo= $this->upload->data();
        return $arquivo['file_name'];


$ attributes = array (‘id’ = > ‘frmCadastro’, ‘name’ => ‘frmCadastro’);
            echo form_open_multipart (‘script / add’, $ attributes);
            echo form_fieldset (‘Register Script’);
            $ attributes = ”;

        $atributos= array('name'=>'lblTutorial', 'id'=>'lblTutorial', 'class'=>'control-label');
        echo form_label('Upload Tutorial', '', $atributos);

        $atributos= array('id'=>'tutorial', 'name'=>'tutorial');
        echo form_upload($atributos);
        $atributos= '';     

        $atributos= array('name'=>'lblVideo', 'id'=>'lblVideo');
        echo form_label('Upload do Vídeo', '', $atributos);
        $atributos= ''; 

        $atributos= array('id'=>'video', 'name'=>'video');
        echo form_upload($atributos);

        $atributos= array('name'=>'lblApostila', 'id'=>'lblApostila');
        echo form_label('Upload da Apostila', '', $atributos);
        $atributos= ''; 

        $atributos= array('id'=>'apostila', 'name'=>'apostila');
        echo form_upload($atributos);
        $atributos= '';                 

        $atributos= array('id'=>'cadastrar', 'name'=>'cadastrar'); 
        echo form_submit($atributos, 'Cadastrar');
        $atributos= '';                     
        echo form_fieldset_close();
        echo form_close();


Answer :

I do not know what version of your CodeIgniter you are using, but check the mime-type of the file you are uploading.
If you are using version 2.3 you do not have mp4 as it can be seen in the ‘./application/config/mses.php’ file. What I advise you to do is take a look at the latest version of github link that you already have validation for this file type.

Just remember to check the size of the file, in php.ini settings how much it supports, but I imagine you have already seen.


Leave a Reply

Your email address will not be published. Required fields are marked *