简体   繁体   中英

How to send multiple file name to database and move file to folder? Codeigniter

I want to upload multiple images. But I don't know what I send data to database and how to move files to folder. This is my view :

<div class="form-group">
   <div class="custom-file">
      <input type="file" class="form-control custom-file-input" name="uploadFile[]" id="uploadFile" multiple>
   </div>
</div>

And this is my controller :

public function add_event() {
        // Our calendar data
        $judul = $this->input->post('judul', TRUE);
        $waktu_mulai = $this->input->post('mulai', TRUE);
        $waktu_berakhir = $this->input->post('berakhir', TRUE);
        $lokasi = $this->input->post('lokasi', TRUE);
        $scope = $this->input->post('scope', TRUE);
        $kategori = $this->input->post('kategori', TRUE);
        $satuan_kerja = $this->input->post('satuan_kerja', TRUE);
        $keterangan = $this->input->post('keterangan', TRUE);
        $agenda_pimpinan = $this->input->post('agenda_pimpinan', TRUE);

        // var_dump (count($upload_file)); die;

        for($i = 0; $i < count($upload_file); $i++) {
            $config['upload_path'] = './uploads/';
            $config['allowed_types'] = 'jpg|jpeg|png';
            $config['max_size'] = '500';

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

            $this->KalenderModel->addEvent(array(
                'judul' => $judul,
                'mulai' => $waktu_mulai,
                'berakhir' => $waktu_berakhir,
                'lokasi' => $lokasi,
                'scope' => $scope,
                'satuan_kerja' => $satuan_kerja,
                'keterangan' => $keterangan,
                'kategori' => $kategori,
                'lampiran' => $uploadfile,
                'tampilkan_agenda_pimpinan' => $agenda_pimpinan
            ));
        }

        redirect('agendakerja/kalender');
    } //end function

Can somebody help?

To get all infos you need about files, you can use

$_FILES;

Here is how you can use it.

Then to move your file, there is the function :

bool move_uploaded_file ( string $filename , string $destination );

Here is more infos.

if you want to upload the file in particular folder then use
$this->upload->do_upload($upload_file[0])

and define the path in $config

 $config['upload_path'] = './uploads/';
 $config['allowed_types'] = 'jpg|jpeg|png';
 $config['max_size'] = '500';

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

 $this->upload->initialize($config);

 for($i = 0; $i < count($upload_file); $i++) {

  if($this->upload->do_upload('bot_logo'))
  {
        $this->KalenderModel->addEvent(array(
            'judul' => $judul,
            'mulai' => $waktu_mulai,
            'berakhir' => $waktu_berakhir,
            'lokasi' => $lokasi,
            'scope' => $scope,
            'satuan_kerja' => $satuan_kerja,
            'keterangan' => $keterangan,
            'kategori' => $kategori,
            'lampiran' => $uploadfile,
            'tampilkan_agenda_pimpinan' => $agenda_pimpinan
        ));
    }
    else
    {
        echo this->upload->display_errors();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM