How to insert the name of the files loaded in the database

1
$this->load->library('upload');

    //Configure upload.
    $this->upload->initialize(array(
        "upload_path"   => './public/uploads/album/',
        "allowed_types" => 'mp3',
        "max_size" => '2194304000',
        "overwrite" => 'FALSE'
    ));

    //Perform upload.
    if($this->upload->do_multi_upload("files")) {


        $arr = array(

                'fx_title' => ?????,
                'alb_id'  => $id,
                'user_id'  => $user_id

        );

        $this->db->insert('nmp3_faixas', $arr);
    }    

What would be the code that would return the names of the uploaded files, and write to the database? I'm using the class link

    
asked by anonymous 06.01.2015 / 16:55

1 answer

1

Always look first in the documentation:

$this->load->library('upload');

//Configure upload.
$this->upload->initialize(array(
    "upload_path"   => './public/uploads/album/',
    "allowed_types" => 'mp3',
    "max_size" => '2194304000',
    "overwrite" => 'FALSE'
));

//Perform upload.
if($this->upload->do_multi_upload("files")) {

    // Retorna detalhes dos arquivos enviados
    $upload_info = $this->upload->get_multi_upload_data();  

    // Inicia o array dos dados que serão inseridos
    $arr = array();

    // Varre o array com info. dos arquivos
    for ($i=0; $i < sizeof($upload_info); $i++) {

        // Nome do arquivo em cada elemento
        $fx_title = $upload_info[$i]['file_name'];

        // Adiciona no array para inserir no banco
        $arr[] = array(
            'fx_title' => $fx_title,
            'alb_id'  => $id,
            'user_id'  => $user_id
        );

    }

    // Insert all into db
    $this->db->insert_batch('nmp3_faixas', $arr);

} 

get_multi_upload_data ()

The extended library also comes with a get_multi_upload_data () method that will return the data on each uploaded file as a multi-dimensional array.

link

    
06.01.2015 / 17:12