You are here

function file_entity_file_download in File Entity (fieldable files) 8.2

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

Implements hook_file_download().

File

./file_entity.module, line 304
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)) {
    return NULL;
  }

  // Allow the user to download the file if they have appropriate permissions.
  if ($file
    ->access('view')) {
    return file_get_content_headers($file);
  }
  return -1;
}