Laravel - calculate total size of directory?

假如想象 提交于 2020-04-16 02:18:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!