You are here

function file_download in Drupal 4

Same name and namespace in other branches
  1. 5 includes/file.inc \file_download()
  2. 6 includes/file.inc \file_download()
  3. 7 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.module
Implementation of hook_menu().

File

includes/file.inc, line 581
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 = module_invoke_all('file_download', $filepath);
    if (in_array(-1, $headers)) {
      return drupal_access_denied();
    }
    if (count($headers)) {
      file_transfer($filepath, $headers);
    }
  }
  return drupal_not_found();
}