Drupal hook: hook_file_download
With hook_file_download(), we can get a granular control over files available for download. This is useful especially when you set your file system as private.
You can even delay the file download by some specified seconds!
The basic idea of hook_file_download is to control and manage private file downloads. So, unauthorized users do not get access to those files. One can write his/her own constraints and apply them at the time of file download. Remember this hook works only if the file system is kept private.
<?php
/**
* @param $filepath
* Path of the file, requested to download
* @return array
* The return value should be Boolean. If the current user or the file matches the criteria,
* return file headers, otherwise -1
*/
function hook_file_download($filepath) {
//Your criteria check code goes here,
// return file headers or -1
}
?>

Recent comments
8 weeks 5 days ago