file_download_headers
function file_download_headers
file_download_headers($uri)
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
File
- includes/file.inc, line 2027
- API for handling file uploads and server file management.
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; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!file.inc/function/file_download_headers/7.x