问题
I'm trying to get the total size of $directory in Laravel, so far I've only been able to get the size of a single file using the size function. There doesn't seem to be any examples or documentation of this?
Any input on this would be appreciated, thanks.
回答1:
I don't think you can. Laravel 5 uses Flysystem Library, which has a sole method for retrieving file size. So using Laravel's File Facade (or Flysystem), you're only left with:
$file_size = 0;
foreach( File::allFiles('FULL_PATH_TO_DIR') as $file)
{
$file_size += $file->getSize();
}
echo number_format($file_size / 1048576,2);
来源:https://stackoverflow.com/questions/33507923/laravel-calculate-total-size-of-directory