function hook_file_download


Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/
cis7 system.api.php hook_file_download($uri)
cle7 system.api.php hook_file_download($uri)
elmsmedia7 system.api.php hook_file_download($uri)
icor7 system.api.php hook_file_download($uri)
meedjum_blog7 system.api.php hook_file_download($uri)
mooc7 system.api.php hook_file_download($uri)

Control access to private file downloads and specify HTTP headers.

This hook allows modules enforce permissions on file downloads when the private file download method is selected. Modules can also provide headers to specify information like the file's name or MIME type.


$uri: The URI of the file.

Return value

If the user does not have permission to access the file, return -1. If the user has permission, return an array with the appropriate headers. If the file is not controlled by the current module, the return value should be NULL.

See also


Related topics

8 functions implement hook_file_download()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

ctools_file_download in sites/all/modules/ulmus/ctools/ctools.module
Implementation of hook_file_download()
file_entity_file_download in sites/all/modules/ulmus/file_entity/file_entity.module
Implements hook_file_download().
file_file_download in modules/file/file.module
Implements hook_file_download().
file_test_file_download in modules/simpletest/tests/file_test.module
Implements hook_file_download().
image_file_download in modules/image/image.module
Implements hook_file_download().

... See full list

4 invocations of hook_file_download()
entity_metadata_file_access in sites/all/modules/ulmus/entity/modules/
Access callback for file entities.
file_download in includes/
Menu handler for private file transfers.
image_file_download in modules/image/image.module
Implements hook_file_download().
image_style_deliver in modules/image/image.module
Page callback: Generates a derivative, given a style and image path.


modules/system/system.api.php, line 2920
Hooks provided by Drupal core and the System module.


function hook_file_download($uri) {
  // Check if the file is controlled by the current module.
  if (!file_prepare_directory($uri)) {
    $uri = FALSE;
  if (strpos(file_uri_target($uri), variable_get('user_picture_path', 'pictures') . '/picture-') === 0) {
    if (!user_access('access user profiles')) {
      // Access to the file is denied.
      return -1;
    else {
      $info = image_get_info($uri);
      return array('Content-Type' => $info['mime_type']);