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

Asked

Viewed 332 times

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 code would return the names of the uploaded files, and write to the database ? I am using the class https://github.com/stvnthomas/CodeIgniter-Multi-Upload

  • Ta in the documentation https://github.com/stvnthomas/CodeIgniter-Multi-Upload#get_multi_upload_data get_multi_upload_data(): returns an array with information of the files loaded from there you handle this array and send it to the database.

1 answer

1


Always search the documentation first:

$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 file sent as a multi-dimensional array.

https://github.com/stvnthomas/CodeIgniter-Multi-Upload#get_multi_upload_data

  • It worked, but if I load multiple files, returns only the first.

  • What is your print_r output($upload_info); ?

  • yes, I did exactly as it is there

  • See if it works (see Edit), it scans the array accumulates the data and inserts it into the database.

  • Your code looks perfect, but the problem still persists this time I have the error in the database Unknown column 'fx_title' in 'field list'

  • He’s saying the column fx_title does not exist in the table nmp3_faixas that you informed.

  • Really, silly little mistake I didn’t notice, the table was fx_title in pt, and I didn’t notice. Anyway thanks, it’s working now. ;)

Show 2 more comments

Browser other questions tagged

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