烙印99
这会成功的您也可以传递一个精度,也许您希望它为 0。<?phpfunction 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 ");