Skip to content

Instantly share code, notes, and snippets.

@vinaydotblog
Created March 30, 2012 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinaydotblog/2248374 to your computer and use it in GitHub Desktop.
Save vinaydotblog/2248374 to your computer and use it in GitHub Desktop.
php: Calculate disk space and Conversion without loops
<?php
/* Copied from http://in2.php.net/manual/en/function.disk-free-space.php */
// Calculate Disk space and Conversion without loops
// Output: 31.24 GB
$bytes = disk_free_space(".");
$si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );
$base = 1024;
$class = min((int)log($bytes , $base) , count($si_prefix) - 1);
echo $bytes . '<br />';
echo sprintf('%1.2f' , $bytes / pow($base,$class)) . ' ' . $si_prefix[$class] . '<br />';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment