Error uploading media Codeigniter

1

When attempting to upload any media, the following error always appears: O TIPO DE ARQUIVO NÃO É PERMITIDO . But yes, I put jpg , png , gif , I already changed only to pdf and error persists! Here are codes:

CONTROLLER:

class Midia extends CI_Controller {

    public function __construct() {
        parent:: __construct();
        init_painel();
        esta_logado();
        $this->load->model('midia_model', 'midia');
    }

    public function index(){
        $this->gerenciar();
    }

    public function cadastrar(){
        $this->form_validation->set_rules('nome', 'NOME', 'trim|required|ucfirst');
        $this->form_validation->set_rules('descricao', 'DESCRICAO', 'trim');
    if($this->form_validation->run()==TRUE):
        $upload = $this->midia->do_upload('arquivo');
        if (is_array($upload) && $upload['file_name'] != null):
            $dados = elements(array('nome', 'descricao'), $this->input->post());
            $dados['arquivo'] = $upload['file_name'];
            $this->midia->do_insert($dados);
        else:
            set_msg('msgerro', $upload, 'erro');
            redirect(current_url());
        endif;

    endif;
    set_tema('titulo', 'Upload de mídia');
    set_tema('conteudo', load_modulo('midia', 'cadastrar'));
    load_template();
    }

MODEL:

class Midia_model extends CI_Model {

    public function do_insert($dados=NULL, $redir=TRUE){
        if($dados != NULL):
            $this->db->insert('media', $dados);
            if ($this->db->affected_rows()>0):
                set_msg('msgok','Cadastro efetuado com sucesso','sucesso');
            else:
                set_msg('msgerro','Erro ao inserir dados','erro');
            endif;  

            if($redir) redirect(current_url());
        endif;
    }

    public function do_upload($campo){
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpeg|png|pdf';
        $this->load->library('upload', $config);
        if($this->upload->do_upload($campo)):
            return $this->upload->data();
        else:
            return $this->upload->display_errors();
        endif;
    }

}

VIEW:

 switch ($tela) :
        case 'cadastrar':
            echo '<div class="large-12  columns ">';
            echo breadcrumb();
                erros_validacao();


get_msg('msgok');
            get_msg('msgerro');
            echo form_open_multipart('midia/cadastrar',array('class'=>'custom'));
            echo form_fieldset('Upload de midia');  
            echo '<div class="large-7  columns ">';
            echo form_label('Nome para exibição');
            echo form_input(array('name'=>'nome', 'class'=>'five'), set_value('nome'), 'autofocus');
            echo form_label('Descrição');
            echo form_input(array('name'=>'descricao', 'class'=>'five'), set_value('descricao'));
            echo form_label('Arquivo');
            echo form_upload(array('name'=>'arquivo', 'class'=>'twelve'), set_value('arquivo'));
            echo anchor('midia/gerenciar','Cancelar',array('class'=>'button radius alert espaco'));         
            echo form_submit(array('name'=>'cadastrar','class'=>'button radius'), 'Salvar Dados');
            echo form_fieldset_close();
            echo form_close();
            echo '</div>';
    break;
    
asked by anonymous 19.11.2015 / 13:40

2 answers

1

Friend, this error occurs because the destination where the file is being sent is incorrect, or the destination folder is not allowed to insert the file. Try to verify that the folder's permission is 777 and that its destination path is correct without missing a slash (/).

    
26.02.2016 / 11:52
0

Are you allowed to write to the directory where the files will be saved?

$config['upload_path'] = './uploads/';
    
23.12.2015 / 02:12