Skip to content

Instantly share code, notes, and snippets.

@RohanPhpDev
Created April 2, 2018 17:01
Show Gist options
  • Save RohanPhpDev/8dd9fa465b8b2889663ec4d22c3702dd to your computer and use it in GitHub Desktop.
Save RohanPhpDev/8dd9fa465b8b2889663ec4d22c3702dd to your computer and use it in GitHub Desktop.
function upload($folder_name,$field_name,$allow_type='',$size=500){
//echo $allow;die();
$CI =& get_instance();
$config['upload_path'] = './upload/'.$folder_name;
$config['allowed_types'] = $allow_type;
$config['max_size'] = $size;
$new_name = time().$_FILES[$field_name]['name'];
$config['file_name'] = $new_name;
$CI->load->library('upload', $config);
$CI->upload->overwrite = true;
if ( ! $CI->upload->do_upload($field_name)){
$error = array('status'=>FALSE,'error' => $CI->upload->display_errors());
return($error);
}
else
{
$data = array('status'=>TRUE,'upload_data' => $CI->upload->data());
return($data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment