PHP get file size

echo getSize(get_attached_file($file['ID'])); function getSize($file){ $bytes = filesize($file); $s = array('b', 'Kb', 'Mb', 'Gb'); $e = floor(log($bytes)/log(1024)); return sprintf('%.2f '.$s[$e], ($bytes/pow(1024, floor($e))));}
Prints out the file size of a media file from the wordpress media library. If you are not using wordpress remove get_attached_file() and replace $file['ID'] with $file server path.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.