0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

LaravelのStorageでディレクトリ内のファイルサイズを取得する方法

Posted at

概要

ファイルそのもののサイズではなくディレクトリ内のファイルサイズを取得したい。

方法

ファイルサイズは下記で取得できる。

.php
use Illuminate\Support\Facades\Storage;

$size = Storage::size('file.jpg');

ディレクトリ内のファイルサイズの取得

.php
use Illuminate\Support\Facades\Storage;

//ディレクトリ内の全ファイルを取得
$allFiles = Storage::disk('app')->allFiles($directryName);

$fileSize = 0;
foreach ($allFiles as $key => $value) {
    $fileSize += Storage::disk('app')->size($value);
}
//これ
dump($fileSize);

終わりに

一発で取得できるメソッドを探したのですが見つからず、、、
苦肉の策としてループで取得しました。

引用

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?