Skip to content

Instantly share code, notes, and snippets.

@bangtiray
Last active October 1, 2018 09:24
Show Gist options
  • Save bangtiray/a49521afd9f30a44c5948b6d082a2b66 to your computer and use it in GitHub Desktop.
Save bangtiray/a49521afd9f30a44c5948b6d082a2b66 to your computer and use it in GitHub Desktop.
Script Upload
<?php
/**
prepared by bangtiray (bego official)
buatkan sebuah folder upload di root project CI
*
*/
require APPPATH . 'libraries/REST_Controller.php';
class Upload extends REST_Controller
{
function __construct()
{
parent::__construct();
}
function upload_post(){
if (!empty($_FILES)) {
$fileName = $_FILES['file']['name'];
$config['upload_path'] = './upload/';
$config['file_name'] = $fileName;
$config['allowed_types'] = 'jpg|png';
$config['encrypt_name'] = TRUE;
$config['file_ext_tolower']=TRUE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload("file")) {
$status['error'] =$this->upload->display_errors('', '');
//untuk status kalo format tidak sesuai configurasi
$status['status'] = 2;
} else {
$raw_name = $this->upload->data('raw_name');
$inputFileName = $this->upload->data('file_name');
$file_ext = $this->upload->data('file_ext');
$config['image_library'] = 'gd2';
$config['source_image'] = $this->upload->data('full_path');
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 48;
$config['height'] = 48;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$status['status'] = 1;
}
}else{
$status['error']='Pilih Foto';
$status['status'] = 3;
}
echo json_encode($status);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment