function file_usage_list

Determines where a file is used.


$file: A file object.

Return value

A nested array with usage data. The first level is keyed by module name, the second by object type and the third by the object id. The value of the third level contains the usage count.

See also



Related topics

7 calls to file_usage_list()
FileDeleteTest::testInUse in drupal/modules/simpletest/tests/file.test
Tries deleting a file that is in use.
FilePrivateTestCase::testPrivateFile in drupal/modules/file/tests/file.test
Tests file access for file uploaded to a private node.
FileUsageTest::testGetUsage in drupal/modules/simpletest/tests/file.test
Tests file_usage_list().
file_delete in drupal/includes/
Deletes a file and its database record.
file_field_delete_file in drupal/modules/file/
Decrements the usage count for a file and attempts to delete it.

... See full list


drupal/includes/, line 659
API for handling file uploads and server file management.


function file_usage_list(stdClass $file) {
  $result = db_select('file_usage', 'f')
    ->fields('f', array(
    ->condition('fid', $file->fid)
    ->condition('count', 0, '>')
  $references = array();
  foreach ($result as $usage) {
    $references[$usage->module][$usage->type][$usage->id] = $usage->count;
  return $references;