Format file size
Sunday, May 14th, 2006 at 8:48 am
Convert the size in bytes for a file into a more user-friendly format
<?php
function formatfilesize( $data ) {
// bytes
if( $data < 1024 ) {
return $data . ” bytes”;
}
// kilobytes
else if( $data < 1024000 ) {
return round( ( $data / 1024 ), 1 ) . “k”;
}
// megabytes
else {
return round( ( $data / 1024000 ), 1 ) . ” MB”;
}
}
?>
This entry was posted by Tim
on Sunday, May 14th, 2006 at 8:48 am and is filed under PHP, Web Development.
You can follow any responses to this entry through the RSS 2.0 feed.
You can skip to the end and leave a response. Pinging is currently not allowed.
Leave a Reply
You must be logged in to post a comment. If you don't have an account register one now.