I have a problem with how to upload 2 file input in 1 form CI 3 with different file name. My view code: There is have 2 file input, 1. file_sertifikat and 2. file_rekomendasi
<div class="form-group">
<label for="file_sertifikat">File Sertifikat</label>
<input type="file" name="file_sertifikat" class="form-control" id="file_sertifikat">
<small class="text-danger"><?= form_error('file_sertifikat') ?></small>
</div>
<div class="form-group">
<label for="file_rekomendasi">File Rekomendasi</label>
<input type="file" name="file_rekomendasi" class="form-control" id="file_rekomendasi">
<small class="text-danger"><?= form_error('file_rekomendasi') ?></small>
</div>
My Controller action to save filename to database:
$file_sertifikat = $this->upload_file_sertifikat($this->input->post('file_sertifikat'));
$file_rekomendasi = $this->upload_file_rekomendasi($this->input->post('file_rekomendasi'));
$data = array(
'file_sertifikat' => $file_sertifikat,
'file_rekomendasi' => $file_rekomendasi,
);
$this->perizinan_model->insert_data($data,'perizinan');
redirect('admin/perizinan');
}
and my upload file function:
public function upload_file_sertifikat(){
$config['upload_path'] = './assets/uploads';
$config['file_name'] = 'file_sertifikat_'.rand(1, 99999);
$config['allowed_types'] = 'gif|jpg|png|jpeg|pdf';
$config['remove_space'] = TRUE;
$config['max_size'] = 10048;
$this->load->library('upload', $config);
if($this->upload->do_upload('file_sertifikat')){
return $this->upload->data("file_name");
}else{
return "defaultimg.png";
}
}
public function upload_file_rekomendasi(){
$config['upload_path'] = './assets/uploads';
$config['file_name'] = 'file_rekomendasi_'.rand(1, 99999);
$config['allowed_types'] = 'gif|jpg|png|jpeg|pdf';
$config['remove_space'] = TRUE;
$config['max_size'] = 10048;
$this->load->library('upload', $config);
if($this->upload->do_upload('file_rekomendasi')){
return $this->upload->data("file_name");
}else{
return "defaultimg.png";
}
}
I want to upload that 2 different filename one by one, but my code overwrite the file. Thank before.