Allowed_types error when uploading a file in codeigniter

0

I am working with codeigniter in a project in which I have to upload files in mp3 format, in my local server it works fine and everything, but when uploading to a hosting it generates the following error

The filetype you are attempting to upload is not allowed.

Which I do not understand since I am working in a way as specified in the official documentation, here I leave the code:

public function setAudio()
{
    $id = $this->input->post('cat');
    $file_name = $this->input->post('name');
    $file_size = $this->input->post('size');
    $file_type = $this->input->post('type');
    $file_dur  = $this->input->post('dur');
    $ruta = './assets/archivos/';
    $config['allowed_types'] = 'mp3';
    foreach ($this->Categoria_model->getCatById($id) as $key) {
        $config['upload_path'] = './assets/archivos/'.$key;
        $ruta = $ruta.$key.'/'.$file_name;
    }
    if(!file_exists($ruta))
    {
        $this->load->library('upload', $config);
        if(!$this->upload->do_upload('files'))
        {
            $error = $this->upload->display_errors();
            $this->session->set_flashdata('error',$error);
            //echo ' no se pudo subir nada'.$config['upload_path'].', error==>'.$error;
            $result = array('error' => true, 'mens' => $error, 'estado' => 3);
            echo json_encode($result);
        }
        else
        {
            $data = $this->upload->data();
            $dd = $this->Audio_model->insertAudio($file_name,$ruta,$file_dur,$id,$file_type,$file_size);
            //$estado = $this->Video_model->insertVideo($file_name,$ruta,$file_dur,$id,$file_type,$file_size);
            $result = array('error' => false, 'mens' => 'El archivo '.$file_name.', a sido guardado correctamente.', 'estado' => 1);
            echo json_encode($result);
            //echo 'Nombre=>'.$file_name.', Cat=>'.$key.', peso=>'.$file_size.', tipo=>'.$file_type.', duracion=>'.$file_dur.', ruta ==>'.$ruta.', == dd '.$dd;
        }
    }
    else
    {
        $result = array('error' => true, 'mens' => 'El archivo se encuentra registrado, por favor seleccione otro', 'estado' => 2);
        echo json_encode($result);
    }
}

In my local server I have php 5 and php 7 configured and in both works correctly, but when you install the hosting does not work, the hosting has a version of php 7 equal to the one I have installed, someone can advise me How to solve this?

    
asked by Jhonny Luis 05.05.2018 в 03:13
source

1 answer

0

Initialize your $config settings correctly.

$this->load->library('upload', $config);
$this->upload->initialize($config);
    
answered by 07.05.2018 в 00:00