The Finder Symfony component is powerful, but unfortunately, you cannot sort founded files by size.
See below. I think it could be helpful, for me at least.
<?php
$finder = new Finder();
$finder->files()
->in(__DIR__)
->sort(function (\SplFileInfo $a, \SplFileInfo $b) {
return filesize($a->getRealpath()) < filesize($b->getRealpath());
});
foreach ($finder as $file) {
echo filesize($file->getRealpath()) . PHP_EOL;
}
That's it!