Same name and namespace in other branches
  1. 10 core/lib/Drupal/Core/File/file.api.php \hook_file_download()
  2. 4.7.x developer/hooks/core.php \hook_file_download()
  3. 6.x developer/hooks/core.php \hook_file_download()
  4. 7.x modules/system/system.api.php \hook_file_download()
  5. 8.9.x core/lib/Drupal/Core/File/file.api.php \hook_file_download()
  6. 9 core/lib/Drupal/Core/File/file.api.php \hook_file_download()

Allow file downloads.

Parameters

$file: String of the file's path.

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.

Related topics

3 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.

fileupload_file_download in developer/examples/fileupload.module
Implementation of hook_file_download.
upload_file_download in modules/upload/upload.module
user_file_download in modules/user/user.module
Implementation of hook_file_download().
1 invocation of hook_file_download()
file_download in includes/file.inc
Call modules that implement hook_file_download() to find out if a file is accessible and what headers it should be transferred with. If a module returns -1 drupal_access_denied() will be returned. If one or more modules returned headers the download…

File

developer/hooks/core.php, line 254
These are the hooks that are invoked by the Drupal core.

Code

function hook_file_download($file) {
  if (user_access('access content')) {
    if ($filemime = db_result(db_query("SELECT filemime FROM {fileupload} WHERE filepath = '%s'", file_create_path($file)))) {
      return array(
        'Content-type:' . $filemime,
      );
    }
  }
  else {
    return -1;
  }
}