function download_file_direct_download in DownloadFile 6
Same name and namespace in other branches
- 7.3 download_file.module \download_file_direct_download()
- 7 download_file.module \download_file_direct_download()
- 7.2 download_file.module \download_file_direct_download()
Page who forces the download of the file by changing the header.
Parameters
$fid: The filefield identifier.
1 string reference to 'download_file_direct_download'
- download_file_menu in ./
download_file.module - Implementation of hook_menu().
File
- ./
download_file.module, line 183 - Module to direct download files or images.
Code
function download_file_direct_download($fid) {
$fid = intval($fid);
$file = field_file_load($fid);
if (empty($fid) || empty($file) || !$file['status']) {
return drupal_access_denied();
}
$file_name = $file['filename'];
$headers = array(
'Content-Type: force-download',
'Content-Disposition: attachment; filename="' . $file_name . '"',
'Content-Length: ' . $file['filesize'],
'Content-Transfer-Encoding: binary',
'Pragma: no-cache',
'Cache-Control: must-revalidate, post-check=0, pre-check=0',
'Expires: 0',
'Accept-Ranges: bytes',
);
if (in_array(-1, $headers)) {
return drupal_access_denied();
}
if (count($headers)) {
file_transfer($file['filepath'], $headers);
}
}