/ Published in: PHP
A function to get a files size via curl. Accepts $_path, $_unit, $_float, $_username & $_password; In the listed order.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function file_size($_path, $_unit, $_float = null, $_username = null, $_password = null) { function unit_size($data, $_unit, $_float) { $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]; } else {return $data." B";} // If you want bytes then we just skip to this part } if(isset($userame) && isset($password)) { $headers = array('Authorization: Basic '.base64_encode("$user:$pw")); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } return unit_size($size, $_unit, $_float); }