1 回答
TA贡献1829条经验 获得超13个赞
这会成功的
您也可以传递一个精度,也许您希望它为 0。
<?php
function human_filesize($size, $precision = 2) {
$units = ['B','kB','MB','GB','TB','PB','EB','ZB','YB'];
$step = 1024;
$i = 0;
while (($size / $step) > 0.9) {
$size = $size / $step;
$i++;
}
return round($size, $precision).$units[$i];
}
function getFileSizeFromUrl($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
$data = curl_exec($ch);
$size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch);
return human_filesize($size);
}
echo getFileSizeFromUrl(" YOUR URL HERE ");
- 1 回答
- 0 关注
- 141 浏览
添加回答
举报