Calculate the size of a file from a URL and display the size in respective units. This function takes a file url and calculates the size the file in php.
function calculateFileSize($url){
$size = filesize($url);
if($size>=1073741824) {
$fileSize = round($size/1024/1024/1024,1).'GB';
} elseif($size>=1048576) {
$fileSize = round($size/1024/1024,1).'MB';
} elseif($size>=1024) {
$fileSize = round($size/1024,1).'KB';
} else {
$fileSize = $size.' bytes';
}
return $fileSize;
}
function calculateFileSize($url){
$size = filesize($url);
if($size>=1073741824) {
$fileSize = round($size/1024/1024/1024,1).'GB';
} elseif($size>=1048576) {
$fileSize = round($size/1024/1024,1).'MB';
} elseif($size>=1024) {
$fileSize = round($size/1024,1).'KB';
} else {
$fileSize = $size.' bytes';
}
return $fileSize;
}
No comments:
Post a Comment