0

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?

1

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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();
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.