Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function simpanproduk_post()
- {
- $toko_id = trim($this->post('toko_id'));
- $nama = trim(strtoupper($this->post('nama')));
- $desc = trim($this->post('desc'));
- $spesifikasi = trim(strtoupper($this->post('spesifikasi')));
- $tipe = trim($this->post('tipe'));
- $sertifikat = trim(strtoupper($this->post('sertifikat')));
- $panen = trim(strtoupper($this->post('panen')));
- $kapasitas = $this->post('kapasitas');
- $stok = $this->post('stok');
- $luas = $this->post('luas');
- $harga = $this->post('harga');
- if ($toko_id == '') {
- $response = [
- 'resp_error' => true,
- 'resp_msg' => 'ID Toko Kosong.',
- ];
- $this->response($response, 403);
- } elseif ($nama == '') {
- $response = [
- 'resp_error' => true,
- 'resp_msg' => 'Nama Produk harus diisi.',
- ];
- $this->response($response, 403);
- } elseif ($desc == '') {
- $response = [
- 'resp_error' => true,
- 'resp_msg' => 'Deskripsi Produk harus diisi.',
- ];
- $this->response($response, 403);
- } elseif ($spesifikasi == '') {
- $response = [
- 'resp_error' => true,
- 'resp_msg' => 'Spesifikasi harus diisi.',
- ];
- $this->response($response, 403);
- } elseif ($tipe == '') {
- $response = [
- 'resp_error' => true,
- 'resp_msg' => 'Tipe harus dipilih.',
- ];
- $this->response($response, 403);
- } elseif ($sertifikat == '') {
- $response = [
- 'resp_error' => true,
- 'resp_msg' => 'Sertifikat harus diisi.',
- ];
- $this->response($response, 403);
- } elseif ($panen == '') {
- $response = [
- 'resp_error' => true,
- 'resp_msg' => 'Jadwal Panen harus diisi.',
- ];
- $this->response($response, 403);
- } elseif ($kapasitas == '') {
- $response = [
- 'resp_error' => true,
- 'resp_msg' => 'Kapasitas harus diisi.',
- ];
- $this->response($response, 403);
- } elseif ($stok == '') {
- $response = [
- 'resp_error' => true,
- 'resp_msg' => 'Stok harus diisi.',
- ];
- $this->response($response, 403);
- } elseif ($luas == '') {
- $response = [
- 'resp_error' => true,
- 'resp_msg' => 'Luas Lahan harus diisi.',
- ];
- $this->response($response, 403);
- } elseif ($harga == '') {
- $response = [
- 'resp_error' => true,
- 'resp_msg' => 'Harga harus diisi.',
- ];
- $this->response($response, 403);
- } else {
- $this->load->library('image_lib');
- if (!empty($_FILES['attachment']['name'])) {
- $jam = time();
- $name = seo_title($nama);
- $config['file_name'] = 'Produk_' . $name . '_' . $jam . '.jpg';
- $config['upload_path'] = './img/produk_folder/';
- $config['allowed_types'] = 'jpg|png|gif|jpeg';
- $config['overwrite'] = true;
- $config['max_size'] = 2048; // 2MB
- $config['max_width'] = 800; // 800 pixel
- $config['max_height'] = 800; // 800 pixel
- $this->load->library('upload');
- $this->upload->initialize($config);
- if (!$this->upload->do_upload('attachment')) {
- $response = [
- 'resp_error' => true,
- 'resp_msg' => 'Error File',
- ];
- $this->response($response, 403);
- } else {
- $upload = $this->upload->do_upload('attachment');
- $upload_data = $this->upload->data();
- $config = array(
- 'file_name' => $upload_data['file_name'],
- 'source_image' => $upload_data['full_path'], //path to the uploaded image
- 'new_image' => $this->resized_path, //path to
- 'maintain_ratio' => true,
- 'overwrite' => true,
- 'width' => 800,
- 'height' => 800,
- );
- $this->image_lib->initialize($config);
- $this->image_lib->resize();
- $config = array(
- 'source_image' => $upload_data['full_path'],
- 'new_image' => $this->thumbs_path,
- 'maintain_ratio' => true,
- 'overwrite' => true,
- 'width' => 400,
- 'height' => 400,
- );
- $this->image_lib->initialize($config);
- $this->image_lib->resize();
- $data = array(
- 'toko_id' => $toko_id,
- 'produk_nama' => $nama,
- 'produk_seo' => seo_title($nama),
- 'produk_desc' => $desc,
- 'produk_spek' => $spesifikasi,
- 'produk_tipe' => $tipe,
- 'produk_sertifikat' => $sertifikat,
- 'produk_panen' => $panen,
- 'produk_kapasitas' => intval(str_replace(",", "", $kapasitas)),
- 'produk_stok' => intval(str_replace(",", "", $stok)),
- 'produk_luas' => intval(str_replace(",", "", $luas)),
- 'produk_harga' => intval(str_replace(",", "", $harga)),
- 'produk_gambar' => $this->upload->file_name,
- 'produk_update' => date('Y-m-d H:i:s'),
- );
- $this->db->insert('simastani_produk', $data);
- $response = [
- 'resp_error' => false,
- 'resp_msg' => 'Simpan Data Berhasil',
- ];
- $this->response($response, 200);
- }
- } else {
- $response = [
- 'resp_error' => false,
- 'resp_msg' => 'Gambar Produk Kosong',
- ];
- $this->response($response, 403);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement