function file_download_headers

Retrieves headers for a private file download.

Calls all module implementations of hook_file_download() to retrieve headers for files by the module that originally provided the file. The presence of returned headers indicates the current user has access to the file.


$uri: The URI for the file whose headers should be retrieved.

Return value

If access is allowed, headers for the file, suitable for passing to file_transfer(). If access is not allowed, an empty array will be returned.

See also




Related topics

3 calls to file_download_headers()
file_download in drupal/includes/
Menu handler for private file transfers.
file_download_access in drupal/includes/
Checks that the current user has access to a particular file.
image_style_deliver in drupal/modules/image/image.module
Page callback: Generates a derivative, given a style and image path.


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


function file_download_headers($uri) {

  // Let other modules provide headers and control access to the file.
  // module_invoke_all() uses array_merge_recursive() which merges header
  // values into a new array. To avoid that and allow modules to override
  // headers instead, use array_merge() to merge the returned arrays.
  $headers = array();
  foreach (module_implements('file_download') as $module) {
    $function = $module . '_file_download';
    $result = $function($uri);
    if ($result == -1) {

      // Throw away the headers received so far.
      $headers = array();
    if (isset($result) && is_array($result)) {
      $headers = array_merge($headers, $result);
  return $headers;