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.
Parameters
$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 includes/
file.inc  - Menu handler for private file transfers.
 - file_download_access in includes/
file.inc  - Checks that the current user has access to a particular file.
 - image_style_deliver in modules/
image/ image.module  - Page callback: Generates a derivative, given a style and image path.
 
File
- 
              includes/
file.inc, line 2116  
Code
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();
      break;
    }
    if (isset($result) && is_array($result)) {
      $headers = array_merge($headers, $result);
    }
  }
  return $headers;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.