Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Custom Helper Function Creted By VeeRa
- *
- * @package CodeIgniter
- * @author VeeRa
- *
- */
- // hashid function for id encryption
- if (!function_exists('hashid'))
- {
- function hashid($string, $action = 'e')
- {
- $secret_key = '*BTzH38rZvEF';
- $secret_iv = 'e3!eWt7oasLp';
- $output = false;
- $encrypt_method = "AES-256-CBC";
- $key = hash( 'sha256', $secret_key );
- $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 );
- if( $action == 'e' ) {
- $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
- }
- else if( $action == 'd' ){
- $output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
- }
- return $output;
- }
- }
- // time elapsed ex. "2 min ago"
- if (!function_exists('time_elapsed_string'))
- {
- /**
- * [time_elapsed_string description]
- * @param [type] $datetime [description]
- * @param boolean $full [description]
- * @return [string] [description]
- */
- function time_elapsed_string($datetime, $full = false)
- {
- $now = new DateTime;
- $ago = new DateTime($datetime);
- $diff = $now->diff($ago);
- $diff->w = floor($diff->d / 7);
- $diff->d -= $diff->w * 7;
- $string = array(
- 'y' => 'year',
- 'm' => 'month',
- 'w' => 'week',
- 'd' => 'day',
- 'h' => 'hour',
- 'i' => 'minute',
- 's' => 'second',
- );
- foreach ($string as $k => &$v) {
- if ($diff->$k) {
- $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
- } else {
- unset($string[$k]);
- }
- }
- if (!$full) $string = array_slice($string, 0, 1);
- return $string ? implode(', ', $string) . ' ago' : 'just now';
- }
- }
- //OTP Generate
- if(!function_exists("otp_generate"))
- {
- /**
- * [otp_generate description]
- * @param integer $length [default length is 6 digit]
- * @return [integer] [random digit]
- */
- function otp_generate($length=6)
- {
- if(is_numeric($length))
- {
- $chars = "0123456789";
- $otp = substr(str_shuffle($chars), 0, $length);
- return $otp;
- }
- }
- }
- // date Format Change dd-mm-yyyy to yyyy-mm-dd
- if(!function_exists("dateFormatSQL"))
- {
- /**
- * [dateFormatSQL description]
- * @param string $date [description]
- * @return [type] [description]
- */
- function dateFormatSQL($date="")
- {
- if($date !="")
- {
- $output = date_format(date_create_from_format('d-m-Y', $date), 'Y-m-d');
- return $output;
- }
- }
- }
- // date Format Change yyyy-mm-dd to dd-mm-yyyy
- if(!function_exists("dateFormatPHP"))
- {
- /**
- * [dateFormatPHP description]
- * @param string $date [description]
- * @return [date] [description]
- */
- function dateFormatPHP($date="")
- {
- if($date !="")
- {
- $output = date_format(date_create_from_format('Y-m-d', $date), 'd-m-Y');
- return $output;
- }
- }
- }
- // SQL DateTime
- if(!function_exists("SQL_DT"))
- {
- function SQL_DT()
- {
- return date('Y-m-d H:i:s');
- }
- }
- // 24hr_to_12hr
- if(!function_exists("time_in_12_hour_format"))
- {
- /**
- * [time_in_12_hour_format description]
- * @param [type] $time [description]
- * @return [type] [description]
- */
- function time_in_12_hour_format($time)
- {
- return date("g:i A", strtotime($time));
- // Input : 08:12
- // Output : 08:12 AM/PM
- }
- }
- // 12hr_to_24hr
- if(!function_exists("time_in_24_hour_format"))
- {
- function time_in_24_hour_format($time)
- {
- return date("H:i", strtotime($time));
- // Input : 08:12 AM/PM
- // Output : 08:12
- }
- }
- if(!function_exists("filesize_formatted"))
- {
- function filesize_formatted($path)
- {
- $size = filesize($path);
- $units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
- $power = $size > 0 ? floor(log($size, 1024)) : 0;
- return number_format($size / pow(1024, $power), 2, '.', ',') . ' ' . $units[$power];
- }
- }
- if(!function_exists("send_sms_api"))
- {
- /**
- * [send_sms_api description]
- * @param [string] $msg [description]
- * @param [string] $mobile [description]
- * @return [type] [description]
- */
- function send_sms_api($message, $mobileNumber)
- {
- //Your authentication key
- $authKey = "";
- //Multiple mobiles numbers separated by comma
- // $mobileNumber = "9999999";
- //Sender ID, While using route4 sender id should be 6 characters long.
- $senderId = "";
- //Your message to send, Add URL encoding here.
- // $message = urlencode("Test message");
- //Define route
- $route = "4";
- //Country
- $country = "91";
- //Prepare you post parameters
- $postData = array(
- 'authkey' => $authKey,
- 'mobiles' => $mobileNumber,
- 'message' => $message,
- 'sender' => $senderId,
- 'route' => $route,
- 'country' => $country
- );
- //API URL
- $url="http://api.msg91.com/api/sendhttp.php";
- // init the resource
- $ch = curl_init();
- curl_setopt_array($ch, array(
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_POST => true,
- CURLOPT_POSTFIELDS => $postData
- //,CURLOPT_FOLLOWLOCATION => true
- ));
- //Ignore SSL certificate verification
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- //get response
- $output = curl_exec($ch);
- //Print error if any
- // if(curl_errno($ch))
- // {
- // echo 'error:' . curl_error($ch);
- // }
- curl_close($ch);
- // echo $output;
- }
- }
- // Single File Upload
- if(!function_exists("file_upload"))
- {
- /**
- * [file_upload description]
- * @param [string] $path [ folder path ]
- * @param [string] $file [ upload controller whole array ]
- * @param [string] $allowed_types [ example : "jpg|jpeg|png|webp" ]
- * @return [string] [ file_name ]
- */
- function file_upload($path, $file, $allowed_types)
- {
- $ci =& get_instance();
- // Make Folder
- if(file_exists(FCPATH.$path)){
- // echo ("$file is a directory");
- }else{
- mkdir(FCPATH.$path, 0777, true);
- // echo ("$file is not a directory");
- }
- $name = explode('.', $file['name']);
- $filename = time().rand(1000,9999).'.'.end($name);
- $config = array(
- 'upload_path' => $path,
- 'upload_url' => base_url().$path,
- 'allowed_types' => $allowed_types,
- 'file_name' => $filename
- );
- $ci->load->library('upload', $config);
- $ci->upload->initialize($config);
- $_FILES['image']['name'] = $file['name'];
- $_FILES['image']['type'] = $file['type'];
- $_FILES['image']['tmp_name'] = $file['tmp_name'];
- $_FILES['image']['error'] = $file['error'];
- $_FILES['image']['size'] = $file['size'];
- if ($ci->upload->do_upload("image"))
- {
- $ci->upload->data();
- } else {
- // return false;
- return $ci->upload->display_errors();;
- }
- return $filename;
- }
- }
- // Multiple File Upload
- if(!function_exists("file_upload_multi"))
- {
- /**
- * [file_upload_multi description]
- * @param [type] $path [ folder path ]
- * @param [type] $files [ upload controller whole array ]
- * @param [type] $allowed_types [ example : "jpg|jpeg|png|webp" ]
- * @return [type] [ file_name ]
- */
- function file_upload_multi($path, $files, $allowed_types)
- {
- $ci =& get_instance();
- // Make Folder
- if(file_exists(FCPATH.$path)){
- // echo ("$file is a directory");
- }else{
- mkdir(FCPATH.$path, 0777, true);
- // echo ("$file is not a directory");
- }
- $config = array(
- 'upload_path' => $path,
- 'upload_url' => base_url().$path,
- 'allowed_types' => $allowed_types,
- );
- $ci->load->library('upload', $config);
- $images = array();
- foreach ($files['name'] as $key => $image)
- {
- $_FILES['images[]']['name'] = $files['name'][$key];
- $_FILES['images[]']['type'] = $files['type'][$key];
- $_FILES['images[]']['tmp_name'] = $files['tmp_name'][$key];
- $_FILES['images[]']['error'] = $files['error'][$key];
- $_FILES['images[]']['size'] = $files['size'][$key];
- $name = explode('.', $files['name'][$key]);
- $fileName = time().rand(1000,9999).'.'.end($name);
- $images[] = $fileName;
- $config['file_name'] = $fileName;
- $ci->upload->initialize($config);
- if ($ci->upload->do_upload('images[]'))
- {
- $ci->upload->data();
- } else {
- return false;
- }
- }
- return $images;
- }
- }
- if(!function_exists("get_int_with_zero"))
- {
- public function get_int_with_zero($value)
- {
- // get value = 1
- // return value = 01
- $num_padded = sprintf("%02d", $value);
- return $num_padded;
- }
- }
- function DuplicateMySQLRecord($table, $primary_key_field, $primary_key_val, $update_value_array='')
- {
- $CI = & get_instance();
- /* generate the select query */
- $CI->db->where($primary_key_field, $primary_key_val);
- $query = $CI->db->get($table);
- foreach ($query->result() as $row){
- foreach($row as $key=>$val){
- if($key != $primary_key_field){
- /* $CI->db->set can be used instead of passing a data array directly to the insert or update functions */
- if(array_key_exists($key, $update_value_array)){
- $CI->db->set($key, $update_value_array[$key]);
- }else{
- $CI->db->set($key, $val);
- }
- }//endif
- }//endforeach
- }//endforeach
- /* insert the new record into table*/
- $CI->db->insert($table);
- $insert_id = $CI->db->insert_id();
- return $insert_id;
- // return $CI->db->insert($table);
- }
- getHostByName(getHostName()); // Get Local Area Current IP Address in Windows PC
- // Get Current IP Address in Linux System
- $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
- $res = socket_connect($sock, '8.8.8.8', 53);
- // You might want error checking code here based on the value of $res
- socket_getsockname($sock, $addr);
- socket_shutdown($sock);
- socket_close($sock);
- echo $addr; // Get Current IP HERE
- function delete_folder_files($folder_path = '')
- {
- if(!empty($folder_path))
- {
- //Get a list of all of the file names in the folder.
- $files = glob($folder_path . '/*');
- //Loop through the file list.
- foreach($files as $file)
- {
- //Make sure that this is a file and not a directory.
- if(is_file($file)) {
- //Use the unlink function to delete the file.
- unlink($file);
- }
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment