Hello Reader's!, If you are looking for a code that can give the directory size from a given path, Then you can use below library code for both Windows and Linux hosting:-
If on a Windows Host:
<?
$filePath = 'c:/www/myfolder';
$obj = new COM ( 'scripting.filesystemobject' );
if ( is_object ( $obj ) )
{
$ref = $obj->getfolder ( $filePath );
echo 'Directory: ' . $filePath . ' => Size: ' . $ref->size;
$obj = null;
}
else
{
echo 'fail to detect';
}
?>
And if you are using a Linux Host then correct your code as follows:-
<?
$filePath = './path/var/myfolder';
$io = popen ( '/usr/bin/du -sk ' . $filePath, 'r' );
$size = fgets ( $io, 4096);
$size = substr ( $size, 0, strpos ( $size, "\t" ) );
pclose ( $io );
echo 'Directory: ' . $filePath . ' => Size: ' . $size;
?>
0 Comment(s)