You are here

function file_entity_file_download in File Entity (fieldable files) 7.3

Same name and namespace in other branches
  1. 8.2 file_entity.module \file_entity_file_download()
  2. 7.2 file_entity.module \file_entity_file_download()

Implements hook_file_download().

Related topics

File

./file_entity.module, line 2091
Extends Drupal file entities to be fieldable and viewable.

Code

function file_entity_file_download($uri) {

  // Load the file from the URI.
  $file = file_uri_to_object($uri);

  // An existing file wasn't found, so we don't control access.
  // E.g. image derivatives will fall here.
  if (empty($file->fid)) {
    return NULL;
  }

  // Allow the user to download the file if they have appropriate permissions.
  if (file_entity_access('view', $file)) {
    return file_get_content_headers($file);
  }
  return NULL;
}