Skip to content

Instantly share code, notes, and snippets.

@caratage
Created November 28, 2012 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caratage/4160346 to your computer and use it in GitHub Desktop.
Save caratage/4160346 to your computer and use it in GitHub Desktop.
Format your Filesize in WordPress
// size calculation
$docsize = @filesize( get_attached_file ( $attachment->ID ) );
// show the attachment,
echo $filename . ' — ' . $docsize;
// echoes something like attachment.zip — 13143
// use size_format() instead. start with size calculation
$docsize = @filesize( get_attached_file( $attachment->ID ) );
if (FALSE === $docsize)
$docsize = 0;
else
$docsize = size_format($docsize, 2);
// show the attachment,
echo $filename . ' — ' . $docsize;
// attachment.zip — 13.14 kB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment