PHP Format File Size Convert KB MB GB

Today, We want to share with you PHP Format File Size Convert KB MB GB.In this post we will show you Human Readable File Size with PHP, hear for convert size in bytes to KB, MB, GB in PHP we will give you demo and example for implement.In this post, we will learn about How to Convert File Size to Human Readable Format in PHP with an example.

PHP Format File Size Convert KB MB GB

There are the Following The simple About PHP Format File Size Convert KB MB GB Full Information With Example and source code.

As I will cover this Post with live Working example to develop php check file size before upload, so the $_files size in php for this example is following below.

Simple You can Convert the size in bytes (PHP filesize MB/KB conversion) for a file into a more redable user-friendly format. so You can simple send the data in bytes to this PHP function:


function formatfileConvertsize($value) {

    //convert Bytes Logic
    if($value < 1024) {

        return $value . " bytes";

    //convert Kilobytes Logic
    else if($value < 1024000) {

        return round(($value / 1024 ), 1) . "k";

    //convert Megabytes Logic
    else {
        return round(($value / 1024000), 1) . "MB";



File Size Conversion with PHP

function formatfileConvertsize($bytes, $decimals = 2){
    $size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
    $data = floor((strlen($bytes) - 1) / 3);
    return sprintf("%.{$decimals}f", $bytes / pow(1024, $data)) . @$size[$data];

Convert File Size to Human Readable Format in PHP

simple you can Call the PHP formatfileConvertsize() function and simple pass the filesize in bytes.

// Get file size
$size = filesize('');

// Convert file size
echo formatfileConvertsize($size);

Angular 6 CRUD Operations Application Tutorials

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Format File Size Convert KB MB GB.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1.   Autocomplete Textbox with Multiple Values using jQuery PHP and MySQL
  2.   Limitto Filter using Angular Example
  3.   Laravel 5.7 Get Current Page URL path
  4.   CodeIgniter TCPDF Integration – create pdf page in tcpdf codeigniter
  5.   How to set up File Permissions for Laravel 5
  6.   File Upload - Auto Resize Compress-Reduce image using PHP
  7.   Laravel Get Current DateTime Handling in PHP with Carbon
  8.   Advanced Recursive paths with React Router
  9.   subquery in sql
  10.   Angularjs Get first and last value of list-item (li)