Maximum Upload
This commit is contained in:
39
fonction.php
Normal file
39
fonction.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
function formatBytes($size, $precision = 2)
|
||||
{
|
||||
$base = log($size, 1024);
|
||||
$suffixes = array('', 'KiB', 'MiB', 'GiB', 'TiB');
|
||||
|
||||
return round(pow(1024, $base - floor($base)), $precision) .' '. $suffixes[floor($base)];
|
||||
}
|
||||
|
||||
function convertToBytes(string $from): ?int {
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
||||
$number = substr($from, 0, -2);
|
||||
$suffix = strtoupper(substr($from,-2));
|
||||
|
||||
//B or no suffix
|
||||
if(is_numeric(substr($suffix, 0, 1))) {
|
||||
return preg_replace('/[^\d]/', '', $from);
|
||||
}
|
||||
|
||||
$exponent = array_flip($units)[$suffix] ?? null;
|
||||
if($exponent === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $number * (1024 ** $exponent);
|
||||
}
|
||||
|
||||
function folderSize($dir)
|
||||
{
|
||||
$size = 0;
|
||||
|
||||
foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) {
|
||||
$size += is_file($each) ? filesize($each) : folderSize($each);
|
||||
}
|
||||
|
||||
return $size;
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user