file_space_used

Versions
6
file_space_used($uid = NULL)
7
file_space_used($uid = NULL, $status = FILE_STATUS_PERMANENT)

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

Parameters

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

$status Optional. File Status to return. Combine with a bitwise OR(|) to return multiple statuses. The default status is FILE_STATUS_PERMANENT.

Return value

An integer containing the number of bytes used.

Related topics

▾ 2 functions call file_space_used()

file_validate_size in includes/file.inc
Check that the file's size is below certain limits.
upload_space_used in modules/upload/upload.module
Determine how much disk space is occupied by a user's uploaded files.

Code

includes/file.inc, line 1037

<?php
function file_space_used($uid = NULL, $status = FILE_STATUS_PERMANENT) {
  $query = db_select('file', 'f');
  // Use separate placeholders for the status to avoid a bug in some versions
  // of PHP. @see http://drupal.org/node/352956
  $query->where('f.status & :status1 = :status2', array(':status1' => $status, ':status2' => $status));
  $query->addExpression('SUM(f.filesize)', 'filesize');
  if (!is_null($uid)) {
    $query->condition('f.uid', $uid);
  }
  return $query->execute()->fetchField();
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.