Error while uploading videos to Codeigniter

Asked

Viewed 250 times

3

I am unable 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 Roadmap'); $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();
  • Returns an error or something? and puts the view tbm pf :)

1 answer

1


I don’t know which version of your Codeigniter you are using, but check the mime-type of the file you are sending. If you are using version 2.3 you do not have mp4 in the list of valid mimes as can be seen in the file ./application/config/mimes.php . What I advise is to take a look at the latest version on github https://github.com/EllisLab/CodeIgniter/blob/develop/application/config/mimes.php that already has validation for this type of file.

Just remembering to check the file size, in the settings of php.ini how much it supports, but I imagine you’ve seen it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.