Error uploading videos in CodeIgniter

3

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 .

Controller:

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>";
        $this->load->view('includes/header');           
        $this->load->view('principal');
        $this->load->view('includes/footer');
    }
    else{
        echo "<script>alert('Cadastro não efetuado');</script>";
        $this->load->view('includes/header');           
        $this->$this->load->view('principal');          
        $this->load->view('includes/footer');
    }
}

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'];
        exit();
    }
    else{
        $arquivo= $this->upload->data();
        return $arquivo['file_name'];
    }
}

View:

$ 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();
    
asked by anonymous 21.03.2014 / 14:07

1 answer

1

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.

    
24.03.2014 / 14:43