1 file.inc file_download()

Page callback: Handles 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 backdrop_access_denied() will be returned. If the file exists but no modules responded backdrop_access_denied() will be returned. If the file does not exist backdrop_not_found() will be returned.

See also

hook_file_download()

system_menu()

Related topics

File

core/includes/file.inc, line 2133
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);
    }
    backdrop_access_denied();
  }
  else {
    backdrop_not_found();
  }
  backdrop_exit();
}