Am I crazy? This php script will not divide properly. For me, $bytes is 143266. That's good. That's the right size. God forbid I return ($bytes/1024)...I get some number like 0.00150632..... What is that about? I've been pulling my hair out for like an hour over this!
$bytes is right, but if I do $bytes/1024, it screws up horribly... I'm concerned that $bytes somehow isn't an integer, but php supposedly takes care of it...
function dir_size($dir)
{
$totalsize=0;
if($dirstream = opendir($dir)) // opening the directory
{
while(false!==($filename=readdir($dirstream)))
{
if($filename != "." && $filename != ".." && $filename != ".DS_Store") // ignore stupid things
{ //recursion to find all files/folders
if (is_file($dir."/".$filename))
$totalsize+=filesize($dir."/".$filename);
if (is_dir($dir."/".$filename))
$totalsize+=dir_size($dir."/".$filename);
}
}
}
closedir($dirstream); // be a good script and clean up
/*********
$types = array("B","KB","MB","GB","TB");
$count = 0;
while ($totalsize > 1024)
{
$totalsize /= 1024;
$count++;
}
//return round($bytes,2)." ".$types[$current];
*********/
return $totalsize; //." ".$types[$count];
}
echo(dir_size("../library/"));