You are here

public function FileStorage::spaceUsed in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/file/src/FileStorage.php \Drupal\file\FileStorage::spaceUsed()
  2. 10 core/modules/file/src/FileStorage.php \Drupal\file\FileStorage::spaceUsed()

Determines total disk space used by a single user or the whole filesystem.

Parameters

int $uid: Optional. A user id, specifying NULL returns the total space used by all non-temporary files.

int $status: (Optional) The file status to consider. The default is to only consider files in status FileInterface::STATUS_PERMANENT.

Return value

int An integer containing the number of bytes used.

Overrides FileStorageInterface::spaceUsed

File

core/modules/file/src/FileStorage.php, line 15

Class

FileStorage
File storage for files.

Namespace

Drupal\file

Code

public function spaceUsed($uid = NULL, $status = FileInterface::STATUS_PERMANENT) {
  $query = $this->database
    ->select($this->entityType
    ->getBaseTable(), 'f')
    ->condition('f.status', $status);
  $query
    ->addExpression('SUM([f].[filesize])', 'filesize');
  if (isset($uid)) {
    $query
      ->condition('f.uid', $uid);
  }
  return $query
    ->execute()
    ->fetchField();
}