Laravel-计算目录的总大小? [英] Laravel - calculate total size of directory?

查看:250
本文介绍了Laravel-计算目录的总大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Laravel中获得$ directory的总大小,到目前为止,我只能使用size函数来获得单个文件的大小.似乎没有任何示例或文档?

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.

推荐答案

我认为您不能. Laravel 5使用 Flysystem 库,该库是检索文件大小的唯一方法.因此,使用Laravel的File Facade(或Flysystem),您只剩下:

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);

这篇关于Laravel-计算目录的总大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆