function file_download

7.x file.inc file_download()
5.x file.inc file_download()
6.x file.inc file_download()

Menu handler for private file transfers.

Call modules that implement hook_file_download() to find out if a file is accessible and what headers it should be transferred with. If one or more modules returned headers the download will start with the returned headers. If a module returns -1 drupal_access_denied() will be returned. If the file exists but no modules responded drupal_access_denied() will be returned. If the file does not exist drupal_not_found() will be returned.

See also

system_menu()

Related topics

1 call to file_download()
image_style_deliver in drupal/modules/image/image.module
Page callback: Generates a derivative, given a style and image path.
5 string references to 'file_download'
drupal-6.bare.database.php in drupal/modules/simpletest/tests/upgrade/drupal-6.bare.database.php
Bare installation of Drupal 6.17, for test purposes.
drupal-6.filled.database.php in drupal/modules/simpletest/tests/upgrade/drupal-6.filled.database.php
Filled installation of Drupal 6.17, for test purposes.
file_download_headers in drupal/includes/file.inc
Retrieves headers for a private file download.
image_file_download in drupal/modules/image/image.module
Implements hook_file_download().
system_menu in drupal/modules/system/system.module
Implements hook_menu().

File

drupal/includes/file.inc, line 1990
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();
  $scheme = array_shift($args);
  $target = implode('/', $args);
  $uri = $scheme . '://' . $target;
  if (file_stream_wrapper_valid_scheme($scheme) && file_exists($uri)) {
    $headers = file_download_headers($uri);
    if (count($headers)) {
      file_transfer($uri, $headers);
    }
    drupal_access_denied();
  }
  else {
    drupal_not_found();
  }
  drupal_exit();
}