Same name and namespace in other branches
  1. 4.6.x includes/file.inc \file_download()
  2. 4.7.x includes/file.inc \file_download()
  3. 5.x includes/file.inc \file_download()
  4. 7.x includes/file.inc \file_download()

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 will start with the returned headers. If no modules respond drupal_not_found() will be returned.

Related topics

1 string reference to 'file_download'
system_menu in modules/system/system.module
Implementation of hook_menu().

File

includes/file.inc, line 966
API for handling file uploads and server file management.

Code

function file_download() {

  // Merge remainder of arguments from GET['q'], into relative file path.
  $args = func_get_args();
  $filepath = implode('/', $args);

  // Maintain compatibility with old ?file=paths saved in node bodies.
  if (isset($_GET['file'])) {
    $filepath = $_GET['file'];
  }
  if (file_exists(file_create_path($filepath))) {
    $headers = file_download_headers($filepath);
    if (count($headers)) {
      file_transfer($filepath, $headers);
    }
    else {
      return drupal_access_denied();
    }
  }
  return drupal_not_found();
}