milov.nl

Interaction design • webdevelopment • web art • photography

milov.nl : forum : coding : 'What's wrong with this PHP-script??'

What's wrong with this PHP-script?? 3.14159, 050515 10:51
I have now tried to figure out this simple for hours, but I can't find the solutions. The errors are also strange..



<?php

function dirsize($dir)
{
$list = scandir($dir);
asort($list);
$num = count($list);
$num -= 2; //For deactivating those ".." and "." values
$i = 0;
while ($i < $num)
{
$i++;
if (is_dir($list[$i])) //Decide whether the file in question is a directory
{
$help[0] = $dir;
$help[1] = $list[$i];
$dir = implode('\', $help);
$filesize += dirsize($dir);
}
else
{
$filesize += filesize($list[$i]);
}

return $filesize;
}
}

$dir = "filefolder";
$filesize = dirsize($dir);

die($filesize); // In the end it echoes the dirsize...

?>

 

I'm running on Apache 2 and PHP 5.0.4.

Help!

YYYMKDCCLXXXVII.dsl.saunalahti.fi
Re: What's wrong with this PHP-script?? 3.14159, 050515 10:53
Oh, and it returned the error

Parse error: syntax error, unexpected $end in "path" on line 34

YYYMKDCCLXXXVII.dsl.saunalahti.fi
Re: What's wrong with this PHP-script?? Milo, 050515 11:09
Haven't tested it, but try replacing the single backslash in the implode function call with a double backslash.
milov.demon.nl
Re: What's wrong with this PHP-script?? Mark, 050531 20:57
If this script is going to run on a *nix machine, why don't use the command 'du'?


$dir = '/path/to/dir';
$output = exec('du -s ' . escapeshellarg($dir));
if (preg_match('/^([0-9]+)/', $output, $regs)) {
$size = $regs[1];
} else {
die("Can't calculate size");
}
echo "Size of '{$dir}': {$size}k";
 
melian.xs4all.nl
Re: What's wrong with this PHP-script?? absolut, 050611 01:22
<?

function dirsize($dir) {

$list = scandir($dir);
$num = count($list);
$size=0;
foreach ($list as $directory) {
$fullfilename=$dir."\".$directory;
if (!preg_match("/^\./",$directory)) {
if (is_dir($fullfilename)) {
$size += (float)dirsize($fullfilename);
}
else {
$size += (float)@filesize($fullfilename);
}
}
}

return $size;

}

$dir = "e:\movies";
$size = dirsize($dir);
print $size;

?>
ppp83-237-45-58.pppoe.mtu-net.ru
Re: What's wrong with this PHP-script?? absolut, 050611 01:23
The (float) is needed to break 2Gb limits.
ppp83-237-45-58.pppoe.mtu-net.ru
Pages: 1