PHP code example of codeinc / human-readable-file-size

1. Go to this page and download the library: Download codeinc/human-readable-file-size library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codeinc / human-readable-file-size example snippets



use CodeInc\HumanReadableFileSize\HumanReadableFileSize;

echo HumanReadableFileSize::getHumanSize(filesize('a-file.pdf'));
// outputs 2.88MB 

echo HumanReadableFileSize::getHumanSize(filesize('a-file.pdf'), 1);
// outputs 2.9MB 

echo HumanReadableFileSize::getHumanSize(filesize('a-file.pdf'), 0);
// outputs 3MB


use CodeInc\HumanReadableFileSize\HumanReadableFileSize;

$readableSize = new HumanReadableFileSize();
$readableSize->useNumberFormatter('fr-FR');
$readableSize->setSpaceBeforeUnit();
$readableSize->setByteSymbol('o');
echo $readableSize->compute(filesize('a-file.pdf'), 1);
// outputs 2,9 Mo