function imce_file_download in IMCE 5
Same name and namespace in other branches
- 8.2 imce.module \imce_file_download()
- 8 imce.module \imce_file_download()
- 6.2 imce.module \imce_file_download()
- 6 imce.module \imce_file_download()
- 7 imce.module \imce_file_download()
Implementation of hook_file_download(). support for private downloads.
File
- ./
imce.module, line 739
Code
function imce_file_download($file) {
$serve = variable_get('file_downloads', '') == FILE_DOWNLOADS_PRIVATE && !variable_get('imce_settings_disable_private', 0) && ($path = file_create_path($file)) && file_exists($path);
if (!$serve) {
return;
}
$roles = variable_get('imce_settings_roles', array());
$roles += array(
'user1' => variable_get('imce_settings_user1', array()),
);
$roles += array(
'default' => imce_settings_default(),
);
$imcefile = FALSE;
foreach ($roles as $rid => $set) {
if ($set['shared']) {
if ($set['shared'] == '/' || strpos($file, $set['shared'] . '/') === 0) {
$imcefile = TRUE;
break;
}
}
else {
if (preg_match("/^" . str_replace(array(
'/',
'-',
), array(
'\\/',
'\\-',
), $set['prefix']) . "[0-9]+\\//", $file)) {
$imcefile = TRUE;
break;
}
}
}
if ($imcefile) {
$ctype = ($info = @getimagesize($path)) ? $info['mime'] : (function_exists('mime_content_type') ? mime_content_type($path) : 'application/x-download');
return array(
'Content-type: ' . $ctype,
);
}
}