le he adaptado un trozo de codigo que vi en php.net asi ahora ademas calcula el tamaño menor del mega y mayor , pone la unidad que le corresponda
Código PHP:
<?
// http://localhost/Space_Used.php
//-------------------------------------------------------------------------------------------------
error_reporting( E_ALL );
@set_time_limit( 0 );
//-------------------------------------------------------------------------------------------------
// funciones
function SpaceUsed($dir) {
global $nivel, $total;
for( $i=0; $i<$nivel; $i++ ) echo( " " );
$folder = substr( $dir, 0, strrpos($dir, '/') );
$folder = substr( $folder, strrpos($folder, '/' ) + 1);
echo( $folder . "<br>" );
$nivel++;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if (is_dir($dir.$file) && $file != '.' && $file != '..') {
spaceUsed( $dir.$file.'/' );
}
else {
if( $file != '.' && $file != '..' ) {
$total += filesize($dir.$file);
for( $i=0; $i<$nivel; $i++ ) echo( " " );
echo( $file . "<br>" );
}
}
}
closedir($dh);
$nivel--;
}
}
}
//-------------------------------------------------------------------------------------------------
// main
$path = "./ordena/";
$total = 0;
$nivel = 0;
echo( "<br><pre>" );
SpaceUsed( $path );
if( $total != 0 ) {
$unidad = "bytes";
if ($total > 1024) {
$total = ($total / 1024);
$unidad = "kB"; }// kilobyte
if ($total > 1024) {
$total = ($total / 1024);
$unidad = "MB"; }// megabyte
if ($total > 1024) {
$total = ($total / 1024);
$unidad = "GB"; }// gigabyte
if ($total > 1024) {
$total = ($total / 1024);
$unidad = "TB"; }// terabyte
if ($total > 1024) {
$total = ($total / 1024);
$unidad = "PB"; }// petabyte
if ($total > 1024) {
$total = ($total / 1024);
$unidad = "EB"; }// exabyte
if ($total > 1024) {
$total = ($total / 1024);
$unidad = "ZB"; } // zettabyte
if ($total > 1024) {
$total = ($total / 1024);
$unidad = "YB"; }// yottabyte
$total = round($total, 0);
echo "<br><br> Tamaño total : ".$total." ".$unidad."<br>";
}
echo( "</pre><br>" );
//-------------------------------------------------------------------------------------------------
// end
?>
Un Saludo