Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.0.0

Request #2798 function for human readable filesize conversion
Submitted: 2004-11-19 15:13 UTC Modified: 2011-03-12 00:13 UTC
From: cweiske Assigned: cweiske
Status: Closed Package: File_Util
PHP Version: - OS: -
Roadmaps: (Not assigned)    
Subscription  



Patch human-readabe.phpt Revisions
Revision 2009-08-06 07:57 UTC
Developer cweiske
 
Download patch

--TEST--
Test File_Util::prefixed() to create human readable file sizes
--FILE--
<?php
require_once 'File/Util.php';
$ottgiga = 1.23*1024*1024*1024;
$ttfmega = 2.34*1024*1024;

//default output
echo File_Util::prefixed($ttfmega) . "\n";
echo File_Util::prefixed($ottgiga) . "\n";
//2 decimals
echo File_Util::prefixed($ottgiga, 2) . "\n";
//long name
echo File_Util::prefixed($ottgiga, 2, true) . "\n";
//short name + new style (i)
echo File_Util::prefixed($ottgiga, 2, false, false) . "\n";
echo File_Util::prefixed($ttfmega, 2, false, false) . "\n";
//long and new style (bi)
echo File_Util::prefixed($ottgiga, 2, true, false) . "\n";
?>
--EXPECT--
2,3 MB
1,2 GB
1,23 GB
1,23 gigabytes
1,23 GiB
2,34 MiB
1,23 gigabibytes