<?php

/*
 * Copyright (c) 2018 Earworks.
 * Codeigniter Project Template Modification
 * Please contact our email for more information :
 * contact@earworks.co.id
 */

defined('BASEPATH') OR exit('No direct script access allowed');
if (!function_exists('do_upload')) {

    function do_upload($input = null, $config = array()) {
        $CI = & get_instance();
        $CI->load->helper('string');
        $data = array();
        if (!$config) {
            $config['upload_path'] = IMAGES;
            $config['allowed_types'] = 'gif|jpg|jpeg|png';
            $config['max_size'] = 20000;
            $config['file_name'] = random_string('alpha', 8) . '_' . time();
//            $config['max_width'] = 1024;
//            $config['max_height'] = 768;
        }
        $CI->load->library('upload');
        $CI->upload->initialize($config);
        if (!$CI->upload->do_upload($input)) {
            $data['error'] = $CI->upload->display_errors();
            $data['data'] = null;
        } else {
            $data['error'] = null;
            $data['data'] = $CI->upload->data();
        }
        $data['config'] = $config;
        return $data;
    }

}