public function downloadHeaders($filename = 'unknown', $cType = null, $inline = false, $cLength = null)
{
/* Remove linebreaks from file names. */
$filename = str_replace(array("\r\n", "\r", "\n"), ' ', $filename);
/* Some browsers don't like spaces in the filename. */
if ($this->hasQuirk('no_filename_spaces')) {
$filename = strtr($filename, ' ', '_');
}
/* MSIE doesn't like multiple periods in the file name. Convert all
* periods (except the last one) to underscores. */
if ($this->isBrowser('msie')) {
if ($pos = strrpos($filename, '.')) {
$filename = strtr(substr($filename, 0, $pos), '.', '_') . substr($filename, $pos);
}
/* Encode the filename so IE downloads it correctly. (Bug #129) */
$filename = rawurlencode($filename);
}
/* Content-Type/Content-Disposition Header. */
if ($inline) {
if (!is_null($cType)) {
header('Content-Type: ' . trim($cType));
} elseif ($this->isBrowser('msie')) {
header('Content-Type: application/x-msdownload');
} else {
header('Content-Type: application/octet-stream');
}
header('Content-Disposition: inline; filename="' . $filename . '"');
} else {
if ($this->isBrowser('msie')) {
header('Content-Type: application/x-msdownload');
} elseif (!is_null($cType)) {
header('Content-Type: ' . trim($cType));
} else {
header('Content-Type: application/octet-stream');
}
if ($this->hasQuirk('break_disposition_header')) {
header('Content-Disposition: filename="' . $filename . '"');
} else {
header('Content-Disposition: attachment; filename="' . $filename . '"');
}
}
/* Content-Length Header. Only send if we are not compressing
* output. */
if (!is_null($cLength) && !in_array('ob_gzhandler', ob_list_handlers())) {
header('Content-Length: ' . $cLength);
}
/* Overwrite Pragma: and other caching headers for IE. */
if ($this->hasQuirk('cache_ssl_downloads')) {
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
}
}