Skip navigation
Help

file_usage_list

7 file.inc file_usage_list(stdClass $file)

Determines where a file is used.

Parameters

$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, the third has 'id' and 'count' keys.

See also

file_usage_add()

file_usage_delete()

Related topics

6 calls to file_usage_list()

File

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

Code

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