3

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.

Jone Does
  • 125
  • 1
  • 10

2 Answers2

17

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);
Taha Paksu
  • 15,371
  • 2
  • 44
  • 78
Leo
  • 1,521
  • 12
  • 18
1

laravel 8

  $imageSize = $request->file('file')->getSize();
    $fil->size = number_format($imageSize / 1048576,2);

$file->size DB table Change It With Your Table