Codeigniter media upload error

Asked

Viewed 740 times

1

While trying to upload any media, the following error always appears : O TIPO DE ARQUIVO NÃO É PERMITIDO. But yes, I did jpg, png, gif, I’ve already switched only to pdf and error persists! Follow 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;

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. Check if the folder permission is 777 and your destination path is correct, without missing a bar ( / ).

0

You have write permission in the directory where the files will be saved?

$config['upload_path'] = './uploads/';
  • Yes, I have full control of the folder !

Browser other questions tagged

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