function file_force_file_download in File Force Download 5
Same name and namespace in other branches
- 6.2 file_force.module \file_force_file_download()
- 6 file_force.module \file_force_file_download()
- 7 file_force.module \file_force_file_download()
Implementation of hook_file_download(). This is what adds the headers which activates the force downloading.
File
- ./
file_force.module, line 36
Code
function file_force_file_download($filepath) {
if (!defined('FILE_FORCE_ACTIVE')) {
// Our menu hook wasn't called, so we should ignore this.
return NULL;
}
return array(
'Content-Type: application/octet-stream',
'Content-Disposition: attachment; filename="' . basename($filepath) . '";',
// Content-Length is also a good header to send, as it allows the browser to
// display a progress bar correctly. It looks like on D5, the Upload module
// does this too if it's installed, but not on D6. So let's do it ourselves
// just in case.
// There's a trick for determining the file size for files over 2 GB. Nobody
// should be using this module with files that large, but… the sprintf()
// trickery makes sure the value is correct for files larger than 2GB. See
// note at http://php.net/filesize
'Content-Length: ' . sprintf('%u', filesize($filepath)),
);
}