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();