PHP 8.5.0 Beta 1 available for testing

Voting

: max(nine, eight)?
(Example: nine)

The Note You're Voting On

Anonymous
10 years ago
Here a function to get the size of a file in a human understanding way with decimal separator, thousand separator, decimals...

function convertFileSize($file, $size=null, $decimals=2, $dec_sep='.', $thousands_sep=','){
if (!is_file($file)){
return "El fichero no existe";
}
$bytes = filesize($file);
$sizes = 'BKMGTP';
if (isset($size)){
$factor = strpos($sizes, $size[0]);
if ($factor===false){
return "El tamaño debe ser B, K, M, G, T o P";
}
} else {
$factor = floor((strlen($bytes) - 1) / 3);
$size = $sizes[$factor];
}
return number_format($bytes / pow(1024, $factor), $decimals, $dec_sep, $thousands_sep).' '.$size;
}

Source: http://softontherocks.blogspot.com/2014/11/obtener-el-tamano-de-un-fichero-y.html

<< Back to user notes page

To Top