function hook_file_download in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/File/file.api.php \hook_file_download()
Control access to private file downloads and specify HTTP headers.
This hook allows modules to enforce permissions on file downloads whenever Drupal is handling file download, as opposed to the web server bypassing Drupal and returning the file from a public directory. Modules can also provide headers to specify information like the file's name or MIME type.
Parameters
$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
file_download()
Related topics
5 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.
- config_file_download in core/
modules/ config/ config.module - Implements hook_file_download().
- file_file_download in core/
modules/ file/ file.module - Implements hook_file_download().
- file_test_file_download in core/
modules/ file/ tests/ file_test/ file_test.module - Implements hook_file_download().
- image_file_download in core/
modules/ image/ image.module - Implements hook_file_download().
- image_module_test_file_download in core/
modules/ image/ tests/ modules/ image_module_test/ image_module_test.module
3 invocations of hook_file_download()
- FileDownloadController::download in core/
modules/ system/ src/ FileDownloadController.php - Handles private file transfers.
- ImageStyleDownloadController::deliver in core/
modules/ image/ src/ Controller/ ImageStyleDownloadController.php - Generates a derivative, given a style and image path.
- image_file_download in core/
modules/ image/ image.module - Implements hook_file_download().
File
- core/
lib/ Drupal/ Core/ File/ file.api.php, line 31 - Hooks related to the File management system.
Code
function hook_file_download($uri) {
// Check to see if this is a config download.
$scheme = file_uri_scheme($uri);
$target = file_uri_target($uri);
if ($scheme == 'temporary' && $target == 'config.tar.gz') {
return array(
'Content-disposition' => 'attachment; filename="config.tar.gz"',
);
}
}