Error message
You are browsing documentation for drupal 7.x, which is not supported anymore. Read the updated version of this page for drupal 11.x (the latest version).function 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
Related topics
- File interface
- Common file handling functions.
1 call to file_download()
- image_style_deliver in modules/
image/ image.module - Page callback: Generates a derivative, given a style and image path.
1 string reference to 'file_download'
- system_menu in modules/
system/ system.module - Implements hook_menu().
File
-
includes/
file.inc, line 2078
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;
$uri = file_uri_normalize_dot_segments ($uri);
if (file_stream_wrapper_valid_scheme ($scheme) && is_file ($uri)) {
$headers = file_download_headers ($uri);
if (count ($headers)) {
file_transfer ($uri, $headers);
}
drupal_access_denied ();
}
else {
drupal_not_found ();
}
drupal_exit ();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.