function _tft_download_the_file in Taxonomy File Tree 7
1 string reference to '_tft_download_the_file'
- tft_menu in ./
tft.module - Implementation of hook_menu().
File
- ./
tft.module, line 17 - Module hooks.
Code
function _tft_download_the_file($nid = NULL) {
$node = node_load($nid);
if (empty($node->tft_file[LANGUAGE_NONE][0]['fid'])) {
drupal_not_found();
}
elseif (node_access('view', $node)) {
$file = file_load($node->tft_file[LANGUAGE_NONE][0]['fid']);
// If using private file system check hook_file_download
$schema = file_uri_scheme($file->uri);
if ($schema == 'private') {
$headers = module_invoke_all('file_download', $file->uri);
// If there is no module granting access or one denying access do not grant access
if (empty($headers) || in_array(-1, $headers)) {
drupal_access_denied();
drupal_exit();
}
}
$http_headers = array(
'Content-Type' => $file->filemime,
'Content-Disposition' => 'attachment; filename="' . $file->filename . '"',
);
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
$http_headers['Cache-Control'] = 'must-revalidate, post-check=0, pre-check=0';
$http_headers['Pragma'] = 'public';
}
else {
$http_headers['Pragma'] = 'no-cache';
}
file_transfer($file->uri, $http_headers);
}
else {
drupal_access_denied();
}
return '';
}