首页 > 解决方案 > 如何将多个文件名发送到数据库并将文件移动到文件夹?代码点火器

问题描述

我想上传多张图片。但我不知道我将数据发送到数据库以及如何将文件移动到文件夹。这是我的观点:

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

这是我的控制器:

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

有人可以帮忙吗?

标签: phpcodeigniter

解决方案


要获取您需要的有关文件的所有信息,您可以使用

$_FILES;

这是您可以使用它的方法。

然后移动你的文件,有以下功能:

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

这里有更多信息。


推荐阅读