Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #CONTROLERS FUNGSI MULTI UPLOAD GAMBAR DAN MULTI RESIZE GAMBAR.
- public function proses_tambah()
- {
- $this->_rules(); //manggil fungsi validasi
- $kode = $this->Produk_model->get_kode(); // manggil fungsi id buat id relasi
- $tanggal = date('Y-m-d'); // tanggal
- if ($this->form_validation->run() == FALSE) {
- $this->tambah(); // kembali ke halaman tambah jika form ada yg kosong
- }
- else
- {
- $user_upload_path = 'media/produk/';
- $config['upload_path'] = './media/produk/ori/';
- $config['allowed_types'] = 'gif|jpg|png';
- $config['max_size'] = 1024 * 4;
- //$config['encrypt_name'] = TRUE;
- $this->load->library('upload', $config);
- $result_array = array();
- for ($i = 1; $i <=4; $i++){
- if (!$this->upload->do_upload('gambar_produk'.$i))
- {
- $data['upload_error'] = $this->upload->display_errors();
- }
- else
- {
- array_push($result_array,$this->upload->data());
- $data_upload = $this->upload->data();
- $file_name = $data_upload["file_name"];
- //merubah nama gambar menjadi seperti ini (470x470_nama_gambar.jpg).
- $file_name_thumb1 = '470x470_'.$data_upload['raw_name'].$data_upload['file_ext'];
- $file_name_thumb2 = '300x300_'.$data_upload['raw_name'].$data_upload['file_ext'];
- $file_name_thumb3 = '175x175_'.$data_upload['raw_name'].$data_upload['file_ext'];
- $this->load->library('image_lib');
- //resize1
- $config_resize1['image_library'] = 'gd2';
- $config_resize1['maintain_ratio'] = TRUE;
- $config_resize1['master_dim'] = 'height';
- $config_resize1['quality'] = "100%";
- $config_resize1['source_image'] = './' . $user_upload_path.'ori/'. $file_name;
- $config_resize1['new_image'] = './' . $user_upload_path.'detail/' . $file_name_thumb1;
- $config_resize1['height'] = 470;
- $config_resize1['width'] = 470;
- $this->image_lib->initialize($config_resize1);
- $this->image_lib->resize();
- $this->image_lib->clear();
- //resize2
- $config_resize2['image_library'] = 'gd2';
- $config_resize2['maintain_ratio'] = TRUE;
- $config_resize2['master_dim'] = 'height';
- $config_resize2['quality'] = "100%";
- $config_resize2['source_image'] = './' . $user_upload_path.'ori/' . $file_name;
- $config_resize2['new_image'] = './' . $user_upload_path.'medium/' . $file_name_thumb2;
- $config_resize2['height'] = 300;
- $config_resize2['width'] = 300;
- $this->image_lib->initialize($config_resize2);
- $this->image_lib->resize();
- $this->image_lib->clear();
- //resize3
- $config_resize3['image_library'] = 'gd2';
- $config_resize3['maintain_ratio'] = TRUE;
- $config_resize3['master_dim'] = 'height';
- $config_resize3['quality'] = "100%";
- $config_resize3['source_image'] = './' . $user_upload_path.'ori/' . $file_name;
- $config_resize3['new_image'] = './' . $user_upload_path.'small/' . $file_name_thumb3;
- $config_resize3['height'] = 175;
- $config_resize3['width'] = 175;
- $this->image_lib->initialize($config_resize3);
- $this->image_lib->resize();
- $this->image_lib->clear();
- }
- }
- $data = array(
- 'sku' => $kode,
- 'nama_produk' => $this->input->post('nama_produk',TRUE),
- 'model_tipe' => $this->input->post('model_tipe',TRUE),
- 'stok' => $this->input->post('stok',TRUE),
- 'harga_jual' => $this->input->post('harga_jual',TRUE),
- 'deskripsi' => $this->input->post('deskripsi',TRUE),
- 'spesifikasi' => $this->input->post('spesifikasi',TRUE),
- 'id_kategori' => $this->input->post('id_kategori',TRUE),
- 'gambar_produk' => $result_array[0]['file_name'], //gambar produk utama
- 'tgl_upload' => $tanggal,
- 'meta_title' => $this->input->post('meta_title',TRUE),
- 'meta_desc' => $this->input->post('meta_desc',TRUE),
- 'meta_keyword' => $this->input->post('meta_keyword',TRUE),
- 'status_tampil' => $this->input->post('status_tampil',TRUE),
- );
- $data_gambar = array(
- 'gambar_1' => $result_array[1]['file_name'], //gambar produk galeri
- 'gambar_2' => $result_array[2]['file_name'], //gambar produk galeri
- 'gambar_3' => $result_array[3]['file_name'], //gambar produk galeri
- 'id_produk' => $kode,
- );
- $this->Produk_model->insert2($data_gambar); // simpan ke tabel galeri produk
- $this->Produk_model->insert1($data); // simpan ke tabel produk
- redirect(site_url('webadmin/produk'));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment