wireBytesStr() function

Given a quantity of bytes (int), return readable string that refers to quantity in bytes, kB, MB, GB and TB

Usage

// basic usage
$string = wireBytesStr(int $bytes);

// usage with all arguments
$string = wireBytesStr(int $bytes, $small = false, $options = array);

Arguments

NameType(s)Description
bytesint

Quantity in bytes

small (optional)bool, int, array

Make returned string as small as possible? (default=false)

  • true (bool): Yes, make returned string as small as possible.
  • 1 (int): Same as true but with space between number and unit label.
  • Or optionally specify the $options argument here if you do not need the $small argument.
options (optional)array, int

Options to modify default behavior, or if an integer then decimals option is assumed:

  • decimals (int|null): Number of decimals to use in returned value or NULL for auto (default=null). When null (auto) a decimal value of 1 is used when appropriate, for megabytes and higher (3.0.214+).
  • decimal_point (string|null): Decimal point character, or null to detect from locale (default=null).
  • thousands_sep (string|null): Thousands separator, or null to detect from locale (default=null).
  • small (bool): If no $small argument was specified, you can optionally specify it in this $options array.
  • type (string): To force return value as specific type, specify one of: bytes, kilobytes, megabytes, gigabytes, terabytes; or just: b, k, m, g, t. (3.0.148+ only, terabytes 3.0.214+).

Return value

string


Functions methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #520
    In the 520th issue of ProcessWire Weekly we'll check out some of the latest additions to the ProcessWire module's directory, share some highlights from the latest weekly update from Ryan, and more. Read on!
    Weekly.pw / 27 April 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits