Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. public function index_post()
  2.     {  
  3.  
  4.         $foto        = $_FILES['gambar']['name'];
  5.         $email       = $this->post('email');
  6.         $password    = $this->post('password');
  7.  
  8.         if ($foto == '') {
  9.             $foto = 'blank_profile.png';
  10.         } else {
  11.             $config['upload_path']   = './assets/images/'; // lokasi penyimpanan gambar
  12.             $config['allowed_types'] = 'jpg|png|jpeg'; // format gambar yang bisa di upload
  13.  
  14.             $this->load->library('upload', $config);
  15.             if (!$this->upload->do_upload('foto')) {
  16.                 // jika foto gagal di inputkan
  17.                 echo "failed upload foto";
  18.             } else {
  19.                 $foto = $this->upload->data('file_name');
  20.             }
  21.         }
  22.  
  23.         $data = [
  24.             "email" => $email,
  25.             "password" => $password,
  26.             "gambar" => $foto
  27.         ];
  28.  
  29.         if ($this->login->insert($data) > 0) {
  30.             $this->response([
  31.                 'status' => true,
  32.                 'message' => 'data berhasil di tambahkan'
  33.             ], 201);
  34.         } else {
  35.             $this->response([
  36.                 'status' => false,
  37.                 'message' => 'data gagal ditambahkan'
  38.             ], 400);
  39.         }
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement