Me acabo de dar cuenta de que la carpeta de pruebas me ocupa más de 2 Gb.
Este es el fuente:
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 = "./";
$total = 0;
$nivel = 0;
echo( "<br><pre>" );
SpaceUsed( $path );
if( $total != 0 ) {
$total /= 1048576;
echo( "<br><br> total = " . round($total, 1) . " Mb<br>" );
}
echo( "</pre><br>" );
//-------------------------------------------------------------------------------------------------
// end
?>