1 file.inc | 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
- core/
includes/ file.inc, line 2273 - 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;
}