function file_force_file_download in File Force Download 6
Same name and namespace in other branches
- 5 file_force.module \file_force_file_download()
- 6.2 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 62 - file_force.module
Code
function file_force_file_download($filepath) {
if (!isset($_GET['download'])) {
// Our menu hook wasn't called, so we should ignore this.
return NULL;
}
$filepath = file_create_path($filepath);
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.
// 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)),
);
}