Array.php
8 years ago
Date.php
8 years ago
File.php
8 years ago
Html.php
8 years ago
Icon.php
8 years ago
Image.php
8 years ago
Network.php
8 years ago
Post.php
8 years ago
String.php
8 years ago
Taxonomy.php
8 years ago
User.php
8 years ago
File.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | class AC_Helper_File { |
| 8 | |
| 9 | /** |
| 10 | * Convert file size to readable format |
| 11 | * |
| 12 | * @since 1.4.5 |
| 13 | * |
| 14 | * @param string $size Size in bytes |
| 15 | * @param int $decimals |
| 16 | * |
| 17 | * @return string|false Readable file size |
| 18 | */ |
| 19 | public function get_readable_filesize( $bytes, $decimals = 2, $empty_text = false ) { |
| 20 | if ( ! $bytes ) { |
| 21 | return $empty_text; |
| 22 | } |
| 23 | |
| 24 | $filesize_units = array( 'Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ); |
| 25 | |
| 26 | $i = (int) floor( log( $bytes, 1024 ) ); |
| 27 | |
| 28 | return round( $bytes / pow( 1024, $i ), $decimals ) . ' ' . $filesize_units[ $i ]; |
| 29 | } |
| 30 | |
| 31 | } |
| 32 |