Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Controller :
- public function savedata() {
- $this->form_validation->set_rules('namarestaurant', '<b>Nama Restaurant</b>','trim|required|min_length[5]|max_length[50]|is_unique[restaurant.nama_restaurant]');
- $this->form_validation->set_rules('deskripsi', '<b>Deskripsi</b>','trim|required|min_length[10]');
- if ($this->form_validation->run() == FALSE) {
- $this->template_admin->display('a/addrestaurant');
- } else {
- // Buat nampung data image yg berhasil diupload
- $upload_data = array();
- // Default konfigurasi, biar nggak perlu nulis ulang :v
- $upload_conf = array(
- 'upload_path' => './restoran/',
- 'allowed_types' => 'gif|jpg|png',
- 'overwrite' => TRUE,
- );
- // File 1
- if (isset($_FILES['userfile'])) {
- $upload_conf['overwrite'] = url_title($this->input->post('userfile'));
- // Load upload lib
- $this->load->library('upload', $upload_conf);
- // Pastiin uploadnya berhasil
- if ($this->upload->do_upload('userfile')) {
- // ngedapetin data hasil upload
- $upload_data['userfile'] = $this->upload->data();
- }
- } else {
- $upload_data['userfile'] = "";
- }
- // File 2
- if (isset($_FILES['userfile1'])) {
- $upload_conf['overwrite'] = url_title($this->input->post('userfile1'));
- // Load upload lib
- $this->load->library('upload', $upload_conf);
- // Pastiin uploadnya berhasil
- if ($this->upload->do_upload('userfile1')) {
- // ngedapetin data hasil upload
- $upload_data['userfile1'] = $this->upload->data();
- }
- } else {
- $upload_data['userfile1'] = "";
- }
- // mastiin kalo data hasil uploadnya udah siap
- if (!empty($upload_data)) {
- // Default image lib config. lagi, biar nggak perlu nulis ulang.
- $imglib_conf = array(
- 'image_library' => 'gd2',
- 'maintain_ratio' => TRUE,
- 'width' => 600,
- 'height' => 360,
- );
- // olah image hasil upload,
- foreach ($upload_data as $id => $img_data) {
- // ambil source image dari $upload_data
- $imglib_conf['source_image'] = $img_data['full_path'];
- // Load image_lib class
- $this->load->library('image_lib', $imglib_conf);
- // resizing
- $this->image_lib->resize();
- }
- }
- $data = array(
- 'nama' => ucwords($this->input->post('namarestaurant')),
- 'deskripsi' => $this->input->post('deskripsi'),
- 'foto1' => '',
- 'foto2' => ''
- );
- if (isset($_FILES['userfile'])) {
- $data['foto1'] = $upload_data['userfile']['file_name'];
- }
- if (isset($_FILES['userfile1'])) {
- $data['foto2'] = $upload_data['userfile1']['file_name'];
- }
- $this->restaurant_model->insert_data($data);
- redirect(base_url().'a/restaurant');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement