Skip to content

Instantly share code, notes, and snippets.

@crossmaya
Created January 5, 2020 04:02
Show Gist options
  • Save crossmaya/708dc9922e969ee24dc4a0fa3a31352b to your computer and use it in GitHub Desktop.
Save crossmaya/708dc9922e969ee24dc4a0fa3a31352b to your computer and use it in GitHub Desktop.

Revisions

  1. crossmaya created this gist Jan 5, 2020.
    13 changes: 13 additions & 0 deletions formater.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    <?php

    class Formater
    {
    public static function bytesToHuman($bytes)
    {
    $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
    for ($i = 0; $bytes > 1024; $i++) {
    $bytes /= 1024;
    }
    return round($bytes, 2).' '.$units[$i];
    }
    }