function file_space_used

Determines 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. The file status to consider. The default is to only consider files in status FILE_STATUS_PERMANENT.

Return value

An integer containing the number of bytes used.

Related topics

2 calls to file_space_used()
FileSpaceUsedTest::testFileSpaceUsed in modules/simpletest/tests/file.test
Test different users with the default status.
file_validate_size in includes/file.inc
Checks that the file's size is below certain limits.

File

includes/file.inc, line 1438

Code

function file_space_used($uid = NULL, $status = FILE_STATUS_PERMANENT) {
    $query = db_select('file_managed', 'f');
    $query->condition('f.status', $status);
    $query->addExpression('SUM(f.filesize)', 'filesize');
    if (isset($uid)) {
        $query->condition('f.uid', $uid);
    }
    return $query->execute()
        ->fetchField();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.