使用curl获取多种格式文件大小的函数。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用curl获取多种格式文件大小的函数。相关的知识,希望对你有一定的参考价值。
A function to get a files size via curl. Accepts $_path, $_unit, $_float, $_username & $_password; In the listed order.
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); }
以上是关于使用curl获取多种格式文件大小的函数。的主要内容,如果未能解决你的问题,请参考以下文章