Postingan lainnya
Cara Upload dua gambar di codeigniter
saya mau tanya bagaimana cara upload 2 gambar di codeigniter dengan ada validasinya. code saya kok masuknya tetep ke 1 aja yak
public function create() {
$site = $this->mConfig->list_config();
$endBlog = $this->mBlogs->endBlog();
$v = $this->form_validation;
$v->set_rules('setuju','Setuju','required');
$v->set_rules('nama','Nama Lengkap','required');
$v->set_rules('email','Email','required');
$v->set_rules('jenis_kelamin','Jenis Kelamin','required');
$v->set_rules('tempat_lahir','Tempat Lahir','required');
$v->set_rules('tanggal_lahir','Tanggal Lahir','required');
$v->set_rules('kewarganegaraan','Kewarganegaraan','required');
$v->set_rules('agama','Agama','required');
$v->set_rules('status','Status','required');
$v->set_rules('no_ktp','Nomor KTP','required');
$v->set_rules('pekerjaan','Pekerjaan','required');
$v->set_rules('alamat','Alamat','required');
if($v->run()) {
$config['upload_path'] = './assets/upload/image/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000'; // KB
$this->load->library('upload', $config);
if(! $this->upload->do_upload('ktp','foto')) {
$data = array( 'title' => 'Create Anggota - '.$site['nameweb'],
'site' => $site,
'error' => $this->upload->display_errors(),
'isi' => 'admin/anggota/create');
$this->load->view('admin/layout/wrapper',$data);
}else{
$upload_data = array('uploads' =>$this->upload->data());
// Image Editor
$config['image_library'] = 'gd2';
$config['source_image'] = './assets/upload/image/'.$upload_data['uploads']['file_name'];
$this->load->library('image_lib', $config);
$this->image_lib->resize();
//dua
$upload_data_foto = array('uploads' =>$this->upload->data());
// Image Editor
$config['image_library'] = 'gd2';
$config['source_image'] = './assets/upload/image/'.$upload_data_foto['uploads']['file_name'];
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$i = $this->input;
$data = array( 'anggota_id' => $i->post('anggota_id'),
'nama' => $i->post('nama'),
'email' => $i->post('email'),
'jenis_kelamin' => $i->post('jenis_kelamin'),
'tempat_lahir' => $i->post('tempat_lahir'),
'kewarganegaraan'=> $i->post('kewarganegaraan'),
'agama' => $i->post('agama'),
'status' => $i->post('status'),
'no_ktp' => $i->post('no_ktp'),
'pekerjaan' => $i->post('pekerjaan'),
'no_telp' => $i->post('no_telp'),
'alamat' => $i->post('alamat'),
'setuju' => $i->post('setuju'),
'ktp' => $upload_data['uploads']['file_name'],
'foto' => $upload_data_foto['uploads']['file_name'],
'date' => $i->post('date')
);
$this->mAnggota->createAnggota($data);
$this->session->set_flashdata('sukses','Success');
redirect(base_url('admin/anggota/'));
}
}
// Default page
$data = array( 'title' => 'Create Anggota - '.$site['nameweb'],
'site' => $site,
'isi' => 'admin/anggota/create');
$this->load->view('admin/layout/wrapper',$data);
}
Terima Kasih :)
0
2 Jawaban:
Jawaban Terpilih
pada dasarnya CI gak support multifile upload gan.. ini pake libary ini gan https://github.com/anuragrath/CodeIgniter-Multiple-File-Upload
atau ane nemu tutorialnya, < tapi ane belum coba https://belajarphp.net/codeigniter-multiple-upload/
0