file_download

Versions
mediamosa-21
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 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.

See also

hook_file_download()

Related topics

Code

includes/file.inc, line 1580

<?php
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_exists($uri)) {
    // Let other modules provide headers and controls access to the file.
    $headers = module_invoke_all('file_download', $uri);
    if (in_array(-1, $headers)) {
      return drupal_access_denied();
    }
    if (count($headers)) {
      file_transfer($uri, $headers);
    }
  }
  return drupal_not_found();
}
?>