I've added comments around what I added:
PHP Code:
<?php
// Add a variable before the loops
$totalSize = 0;
$dir = "../demo/themes/";
$tree = array();
$dirs = array(array($dir, &$tree));
for($i = 0; $i < count($dirs); ++$i)
{
$d = opendir($dirs[$i][0]);
$tier =& $dirs[$i][1];
while($file = readdir($d))
{
if ($file != '.' and $file != '..')
{
$path = $dirs[$i][0] . DIRECTORY_SEPARATOR . $file;
if (is_dir($path))
{
$tier[$file] = array();
$dirs[] = array($path, &$tier[$file]);
}
else
{
$size2 = filesize($path);
// Add the Size
$totalSize += size2;
$size = array($size2);
print_r($size);
echo "<br>";
}
}
}
}
// Show the size
print $totalSize;
Also, if you are using an array you should push the value so that it goes in as the last/new element. That would keep them from all being on element 0.