I want to get size of all files in one directory.Here is code that i have tried
$files=scandir(__DIR__,1);
echo $files[0]["size"];
This code saves all files in $files
but it saves only its' names not sizes.
I want to get size of all files in one directory.Here is code that i have tried
$files=scandir(__DIR__,1);
echo $files[0]["size"];
This code saves all files in $files
but it saves only its' names not sizes.
you can try this:
function getDirSize($path)
{
$fio = popen('/usr/bin/du -sb '.$path, 'r');
$size = intval(fgets($fio,80));
pclose($fio);
return $size;
}
or
function getDirSize($path) {
$size = 0;
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $file){
$size+=$file->getSize();
}
return $size;
}