Plz guys, help me free my mind...
I have this function:
<?php
function size($dir) {
$size = 0;
if(is_dir($dir)) {
$handle = opendir($dir);
while (($file = readdir($handle)) != false) {
if (($file != ".") && ($file != "..")) {
if (is_dir($dir."/".$file)) {
$size += size($dir."/".$file);
}
if (is_file($dir."/".$file)) {
$size += filesize($dir."/".$file);
}
}
}
closedir($handle);
}
else {
$size += filesize($dir);
}
return $size;
}
//just to see if works
echo size("./");
?>
All right....Echos the total bytes of current directory...But, I want to divide the result by 1024 to get the results in kb:
<?php
function size($dir) {
$size = 0;
if(is_dir($dir)) {
$handle = opendir($dir);
while (($file = readdir($handle)) != false) {
if (($file != ".") && ($file != "..")) {
if (is_dir($dir."/".$file)) {
$size += size($dir."/".$file);
}
if (is_file($dir."/".$file)) {
$size += filesize($dir."/".$file);
}
}
}
closedir($handle);
}
else {
$size += filesize($dir);
}
//line added
$size /= 1024;
return $size;
}
echo size("./");
?>
Looks perfect for me, but when I run the script it returns me a crazy number, which is not the size of directory in Kb...
What's going on here??
Thanx in advance