Advertisement
Guest User

controller

a guest
Jan 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1. public function upload_image(){
  2.         $data['id_boat'] = $this->input->post('id_boat',TRUE);
  3.  
  4.         $temp_file_path = tempnam(sys_get_temp_dir(), 'androidtempimage'); // might not work on some systems, specify your temp path if system temp dir is not writeable
  5.         file_put_contents($temp_file_path , base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $_POST['userfile'])));
  6.         $image_info = getimagesize($temp_file_path);
  7.         $_FILES['userfile'] = array(
  8.              'name' => uniqid().'.'.preg_replace('!\w+/!', '', $image_info['mime']),
  9.              'tmp_name' => $temp_file_path,
  10.              'size'  => filesize($temp_file_path),
  11.              'error' => UPLOAD_ERR_OK,
  12.              'type'  => $image_info['mime']
  13.          );
  14.  
  15.         $config['upload_path']          = './assets/images/boat/';
  16.         $config['allowed_types']        =  'jpg|gif|png|jpeg|JPG|PNG';
  17.         $config['max_size']             = 1000000;
  18.         $config['max_width']            = 10240000;
  19.         $config['max_height']           = 7680000;
  20.  
  21.         $this->load->library('upload', $config);
  22.  
  23.         if ( ! $this->upload->do_upload('userfile',true))
  24.         {
  25.                 $error = array('error' => $this->upload->display_errors(),
  26.                                 'file' => $_FILES['userfile']);
  27.                 echo json_encode($error);              
  28.         }
  29.         else
  30.         {              
  31.                 $photo = $this->upload->data();  
  32.                 $data['foto_boat'] = $photo['file_name'];
  33.                 $update = $this->Boat_model->simpan_ubah($data,$data['id_boat']);  
  34.                 if($update){       
  35.                     $data['status'] = 'Berhasil ubah foto';    
  36.                 }else{
  37.                     $data['status'] = 'Gagal ubah foto';       
  38.                 }          
  39.                 echo json_encode($data);
  40.                
  41.         }
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement