Skip to content

Add a generic formatSize function #7

@technicalguru

Description

@technicalguru

This comes from a previous formatFileSize function. Make this more generic for utilities.

public static function formatFileSize($size) {
		$unit = 'B';
		// Only until GB
		if ($size > 1024) {
			$size = $size/1024;
			$unit = 'KB';
		}
		if ($size > 1024) {
			$size = $size/1024;
			$unit = 'MB';
		}
		if ($size > 1024) {
			$size = $size/1024;
			$unit = 'GB';
		}
		$size = $unit != 'B' ? sprintf('%.1f', $size) : $size;
		return $size.' '.$unit;
	}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions