and like us on FB

PHP’s filesize() function will do as described: get the size of a file in bytes. However, it’s usually necessary to convert that returned value into something more readable, and the PHP functions in this article will accomplish that.

The first function will take a value in bytes and return a human readable string. The B for bytes, K for kilobytes, M for megabytes, etc will be appended, and the decimal value will be truncated to your specified length.

It’s often necessary to include the filesize() functionality into the actual function. The second function will take a file path as an argument and return the human readable size of the referenced file.

If you’re looking to return the size of an entire directory, you’ll find that article here (when published).


Download: PHP Code (V)

Shortt URL for this post: