function file_size($_path, $_unit, $_float = null, $_username = null, $_password = null) {
$_unit = trim(strtoupper($_unit)); //Making the unit compatible
function unit_size($data, $_unit, $_float) {
if (!isset($_float)) {$_float = 3;} // float 3 decimal places by default
$sizes = array("B"=>0, "KB"=>1, "MB"=>2, "GB"=>3, "TB"=>4, "PB"=>5, "EB"=>6, "ZB"=>7, "YB"=>8); //Associated with each unit is the exponent that will be used to do the conversion from bytes
if (array_key_exists($_unit, $sizes) && $sizes[$_unit] != 0) { // If the unit is not bytes we get down to business
$number = $sizes[$_unit];
$total = $data / (pow(1024, $number));
return round($total, $_float)." ".$_unit;
}
else {return $data." B";} // If you want bytes then we just skip to this part
}
$ch = curl_init($_path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
if(isset($userame) && isset($password)) { $headers = array('Authorization: Basic '.base64_encode("$user:$pw")); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); }
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $_path); //specify the ur
$data = curl_exec($ch);
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch);
return unit_size($size, $_unit, $_float);
}