WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/size format

Contents

Description

Convert a given number of bytes into a human readable format, using the largest unit the bytes will fit into.

Parameters

$bytes
(mixed) (required) Number of bytes. Note max integer size for integers. Accepts int or string
Default: None
$decimals
(int) (optional) Precision of number of decimal places. Deprecated.
Default: 0

Return

boolean or string. False on failure. Number string on success.

Usage

 <?php $size_to_display size_format(1024); 

Example

Display the size of a file

$file_size = 1229; // filesize in bytes
echo size_format($file_size, 2); // displays "1.20 kB"


Change Log

Source File

size_format() is located in wp-includes/functions.php.

Related

Function ref links

This article is marked as in need of editing. You can help Codex by editing it.