Created
August 25, 2018 11:32
-
-
Save hamzaali00001/4117c69a9eef89db15c0581a1c676a80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!function_exists('human_file_size')) { | |
/** | |
* Returns a human readable file size | |
* | |
* @param integer $bytes | |
* Bytes contains the size of the bytes to convert | |
* | |
* @param integer $decimals | |
* Number of decimal places to be returned | |
* | |
* @return string a string in human readable format | |
* | |
* */ | |
function human_file_size($bytes, $decimals = 2) | |
{ | |
$sz = 'BKMGTPE'; | |
$factor = (int)floor((strlen($bytes) - 1) / 3); | |
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . $sz[$factor]; | |
} | |
} | |
if (!function_exists('in_arrayi')) { | |
/** | |
* Checks if a value exists in an array in a case-insensitive manner | |
* | |
* @param mixed $needle | |
* The searched value | |
* | |
* @param $haystack | |
* The array | |
* | |
* @param bool $strict [optional] | |
* If set to true type of needle will also be matched | |
* | |
* @return bool true if needle is found in the array, | |
* false otherwise | |
*/ | |
function in_arrayi($needle, $haystack, $strict = false) | |
{ | |
return in_array(strtolower($needle), array_map('strtolower', $haystack), $strict); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment