Spatie\Backup\Helpers\Format::humanReadableSize PHP Méthode

humanReadableSize() public static méthode

public static humanReadableSize ( integer $sizeInBytes ) : string
$sizeInBytes integer
Résultat string
    public static function humanReadableSize(int $sizeInBytes) : string
    {
        $units = ['B', 'KB', 'MB', 'GB', 'TB'];
        if ($sizeInBytes === 0) {
            return '0 ' . $units[1];
        }
        for ($i = 0; $sizeInBytes > 1024; ++$i) {
            $sizeInBytes /= 1024;
        }
        return round($sizeInBytes, 2) . ' ' . $units[$i];
    }

Usage Example

 protected function backupDestinationProperties() : Collection
 {
     $backupDestination = $this->backupDestination();
     if (!$backupDestination) {
         return collect();
     }
     $newestBackup = $backupDestination->newestBackup();
     $oldestBackup = $backupDestination->oldestBackup();
     return collect(['Application name' => $this->applicationName(), 'Disk' => $backupDestination->diskName(), 'Newest backup size' => $newestBackup ? Format::humanReadableSize($newestBackup->size()) : 'No backups were made yet', 'Amount of backups' => strval($backupDestination->backups()->count()), 'Total storage used' => Format::humanReadableSize($backupDestination->backups()->size()), 'Newest backup date' => $newestBackup ? $newestBackup->date()->format('Y/m/d H:i:s') : 'No backups were made yet', 'Oldest backup date' => $oldestBackup ? $oldestBackup->date()->format('Y/m/d H:i:s') : 'No backups were made yet'])->filter();
 }
All Usage Examples Of Spatie\Backup\Helpers\Format::humanReadableSize