Last active
August 29, 2015 14:10
-
-
Save jokosusilo/fbfa0fc6ec65d280ee72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- view --> | |
<input type="file" class="form-control" id="image" name="image" required> | |
<?php | |
// Controller | |
// fungsi insert | |
public function store(){ | |
$config['upload_path'] = './assets/produk/'; | |
$config['allowed_types'] = 'gif|jpg|png'; | |
$config['max_size'] = '20000'; | |
$this->load->library('upload', $config); | |
if ( ! $this->upload->do_upload('image')){ | |
redirect('admin/produk'); | |
} | |
else{ | |
$data = array( | |
'nama_produk' => $this->input->post('nama_produk'), | |
'deskripsi' => $this->input->post('deskripsi'), | |
'image_produk' => $_FILES['image']['name'], | |
); | |
$this->produk->insert($data); | |
redirect('admin/produk'); | |
} | |
} | |
// fungsi update | |
public function update($id){ | |
$config['upload_path'] = './assets/produk/'; | |
$config['allowed_types'] = 'gif|jpg|png'; | |
$config['max_size'] = '20000'; | |
$this->load->library('upload', $config); | |
if ($_FILES['image']['name'] != '') { | |
if ( ! $this->upload->do_upload('image')){ | |
redirect('admin/produk'); | |
} | |
else{ | |
$model = $this->loadModel($id); | |
if ($this->deleteGambar($model->image_produk)) { | |
$data = array( | |
'nama_produk' => $this->input->post('nama_produk'), | |
'deskripsi' => $this->input->post('deskripsi'), | |
'image_produk' => $_FILES['image']['name'], | |
); | |
$this->produk->update($id, $data); | |
redirect('admin/produk'); | |
} | |
} | |
}else{ | |
$data = array( | |
'nama_produk' => $this->input->post('nama_produk'), | |
'deskripsi' => $this->input->post('deskripsi'), | |
); | |
$this->produk->update($id, $data); | |
redirect('admin/produk'); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment