Advertisement
jamboljack

Upload Gambar

Jan 24th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.55 KB | None | 0 0
  1. $jam      = time();
  2.         $username = $this->session->userdata('username');
  3.  
  4.         $config['file_name']     = 'Avatar_' . $username . '_' . $jam . '.jpg';
  5.         $config['upload_path']   = './img/icon/';
  6.         $config['allowed_types'] = 'jpg|png|gif|jpeg';
  7.         $config['overwrite']     = true;
  8.         $config['max_size']      = 0;
  9.         $this->load->library('upload');
  10.         $this->upload->initialize($config);
  11.  
  12.         // Resize
  13.         $configThumb                   = array();
  14.         $configThumb['image_library']  = 'gd2';
  15.         $configThumb['source_image']   = '';
  16.         $configThumb['maintain_ratio'] = true;
  17.         $configThumb['overwrite']      = true;
  18.         $configThumb['width']          = 150;
  19.         $configThumb['height']         = 150;
  20.         $this->load->library('image_lib');
  21.  
  22.         if (!$this->upload->do_upload('foto')) {
  23.             $response['status'] = 'error';
  24.         } else {
  25.             $upload                      = $this->upload->do_upload('foto');
  26.             $upload_data                 = $this->upload->data();
  27.             $name_array[]                = $upload_data['file_name'];
  28.             $configThumb['source_image'] = $upload_data['full_path'];
  29.             $this->image_lib->initialize($configThumb);
  30.             $this->image_lib->resize();
  31.            
  32.             // SImpan Data
  33.             $data = array(
  34.                 'user_avatar'      => $this->upload->file_name,
  35.             );
  36.  
  37.             $this->db->insert('pasar_users', $data);
  38.             $response['status'] = 'success';
  39.         }
  40.  
  41. echo json_encode($response);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement