function filebrowser_filebrowser_download_manager_process in Filebrowser 7.2
Same name and namespace in other branches
- 8 filebrowser.module \filebrowser_filebrowser_download_manager_process()
- 7.4 filebrowser.module \filebrowser_filebrowser_download_manager_process()
- 7.3 filebrowser.module \filebrowser_filebrowser_download_manager_process()
hook_filebrowser_download_manager_process implementation.
File
- ./
filebrowser.module, line 907
Code
function filebrowser_filebrowser_download_manager_process($delta = NULL, $file = NULL, $filename = NULL) {
// Force download option not available in this version
$force_download = null;
$content_disposition = $force_download ? 'Content-Disposition: attachment; filename="' : 'Content-Disposition: inline; filename="';
switch ($delta) {
case 'public':
$web_root = getcwd();
if (strpos($web_root, $file) === 0) {
$target = substr($file, strlen($web_root));
}
else {
$target = $file;
}
header("Location: " . url(trim($target, '/'), array(
'absolute' => TRUE,
)));
return TRUE;
case 'private':
if (ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}
$headers = array(
'Content-Description' => 'File Transfer',
'Cache-Control' => 'public, must-revalidate, max-age=0',
// HTTP/1.1
'Pragma' => 'public',
'Expires' => 'Sat, 26 Jul 1997 05:00:00 GMT',
// Date in the past
'Last-Modified' => gmdate('D, d M Y H:i:s') . ' GMT',
'Content-Type' => file_get_mimetype($filename),
'Content-Transfer-Encoding' => 'binary',
'Content-Length' => filesize($file),
);
if (stristr("MSIE", getenv("HTTP_USER_AGENT")) || stristr("Internet Explorer", getenv("HTTP_USER_AGENT"))) {
$headers['Content-Disposition'] = 'inline; filename="' . mb_convert_encoding(_filebrowser_safe_basename($filename), "ISO-8859-2", "UTF-8") . '";';
}
else {
$content_disposition = $force_download ? 'attachment;' : 'inline;';
$headers['Content-Disposition'] = $content_disposition . ' filename="' . _filebrowser_safe_basename($filename) . '";';
}
if (ob_get_level()) {
ob_end_clean();
}
foreach ($headers as $name => $value) {
drupal_add_http_header($name, $value);
}
drupal_send_headers();
drupal_set_time_limit(0);
// Transfer file in 1024 byte chunks to save memory usage.
if ($fd = fopen($file, 'rb')) {
while (!feof($fd)) {
print fread($fd, 1024);
}
fclose($fd);
}
else {
drupal_not_found();
}
drupal_exit();
}
}