hook_file_download

5 core.php hook_file_download($file)
6 core.php hook_file_download($filepath)
7 system.api.php hook_file_download($uri)
8 system.api.php hook_file_download($uri)

Allow file downloads.

Parameters

$file: String of the file's path.

Return value

If the user does not have permission to access the file, return -1. If the user has permission, return an array with the appropriate headers.

Related topics

3 functions implement hook_file_download()

1 invocation of hook_file_download()

File

developer/hooks/core.php, line 246
These are the hooks that are invoked by the Drupal core.

Code

function hook_file_download($file) {
  if (user_access('access content')) {
    if ($filemime = db_result(db_query("SELECT filemime FROM {fileupload} WHERE filepath = '%s'", file_create_path($file)))) {
      return array('Content-type:' . $filemime);
    }
  }
  else {
    return -1;
  }
}
Login or register to post comments