Assalamualaikum,.. berikut tahapannya :
1. baca Bismillah..
2. ubah type inputan
file menjadi multiple pada
file : application\views\administrator\mod_produk\view_produk_tambah.php baris ini :
<input type='file' class='form-control' name='g'> menjadi :
<input type='file' class='form-control' name='userfile[]' multiple>
Lalu pada action simpan gambar pada controllers tambah_produk() ubah menjadi :
function tambah_produk(){
cek_session_akses('produk',$this->session->id_session);
if (isset($_POST['submit'])){ $files = $_FILES;
$cpt = count($_FILES['userfile']['name']); for($i=0; $i<$cpt; $i++){
$_FILES['userfile']['name']= $files['userfile']['name'][$i];
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];
$this->load->library('upload');
$this->upload->initialize($this->set_upload_options());
$this->upload->do_upload();
$fileName = $this->upload->data()['file_name'];
$images[] = $fileName;
}
if (trim($fileName)!=''){ $data = array('id_kategori_produk'=>$this->input->post('a'), 'nama_produk'=>$this->db->escape_str($this->input->post('b')),
'produk_seo'=>$this->db->escape_str(seo_title($this->input->post('b'))),
'satuan'=>$this->input->post('c'),
'harga_beli'=>$this->input->post('d'),
'harga_reseller'=>$this->input->post('e'),
'harga_konsumen'=>$this->input->post('f'),
'berat'=>$this->input->post('berat'),
'gambar'=>$fileName,
'keterangan'=>$this->input->post('ff'),
'username'=>$this->session->username,
'waktu_input'=>date('Y-m-d H:i:s')); }else{
$data = array('id_kategori_produk'=>$this->input->post('a'), 'nama_produk'=>$this->input->post('b'),
'produk_seo'=>$this->db->escape_str(seo_title($this->input->post('b'))),
'satuan'=>$this->input->post('c'),
'harga_beli'=>$this->input->post('d'),
'harga_reseller'=>$this->input->post('e'),
'harga_konsumen'=>$this->input->post('f'),
'berat'=>$this->input->post('berat'),
'keterangan'=>$this->input->post('ff'),
'username'=>$this->session->username,
'waktu_input'=>date('Y-m-d H:i:s')); }
$this->model_app->insert('rb_produk',$data);
redirect('administrator/produk');
}else{
$data['record'] = $this->model_app->view_ordering('rb_kategori_produk','id_kategori_produk','DESC');
$this->template->load('administrator/template','administrator/mod_produk/view_produk_tambah',$data);
}
}
Lalu tambahkan config uploadnya gambar dibawahnya :
private function set_upload_options(){
$config['upload_path'] = "asset/foto_produk/";
$config['allowed_types'] = 'gif|jpg|png|jpeg|JPG|JPEG|PNG|GIF';
$config['max_size'] = '10000'; // kb
$config['encrypt_name'] = FALSE;
$this->load->library('upload', $config);
return $config;
}
Selesai, tinggal menampilkan gambar pada halaman web utama jadinya begini :
for($i=0; $i<$hitungex; $i++){
echo "<img src='".base_url()."asset/foto_produk/".$ex[$i]."'>";
}