Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function upload_image(){
- $data['id_boat'] = $this->input->post('id_boat',TRUE);
- $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
- file_put_contents($temp_file_path , base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $_POST['userfile'])));
- $image_info = getimagesize($temp_file_path);
- $_FILES['userfile'] = array(
- 'name' => uniqid().'.'.preg_replace('!\w+/!', '', $image_info['mime']),
- 'tmp_name' => $temp_file_path,
- 'size' => filesize($temp_file_path),
- 'error' => UPLOAD_ERR_OK,
- 'type' => $image_info['mime']
- );
- $config['upload_path'] = './assets/images/boat/';
- $config['allowed_types'] = 'jpg|gif|png|jpeg|JPG|PNG';
- $config['max_size'] = 1000000;
- $config['max_width'] = 10240000;
- $config['max_height'] = 7680000;
- $this->load->library('upload', $config);
- if ( ! $this->upload->do_upload('userfile',true))
- {
- $error = array('error' => $this->upload->display_errors(),
- 'file' => $_FILES['userfile']);
- echo json_encode($error);
- }
- else
- {
- $photo = $this->upload->data();
- $data['foto_boat'] = $photo['file_name'];
- $update = $this->Boat_model->simpan_ubah($data,$data['id_boat']);
- if($update){
- $data['status'] = 'Berhasil ubah foto';
- }else{
- $data['status'] = 'Gagal ubah foto';
- }
- echo json_encode($data);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement