public function send($fake_name = null, $server_handled = False, $content_type = null)
{
if ($this->getIsFile()) {
if ($this->getReadable() && !headers_sent()) {
if ($content_type) {
$ctype = $content_type;
} else {
$ctype = $this->getMimeType();
if (!$ctype) {
$ctype = 'application/octet-stream';
}
}
if ($fake_name) {
$filename = $fake_name;
} else {
$filename = $this->getBasename();
}
// Disable browser caching.
header('Cache-control: private');
header('Pragma: private');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-Type: ' . $ctype);
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . $this->getSize(False));
header('Content-Disposition: attachment;filename="' . $filename . '"');
if ($server_handled) {
header('X-Sendfile: ' . $this->_realpath);
} else {
if ($contents = $this->getContents()) {
echo $contents;
}
}
exit;
}
$this->addLog('Unable to prepare file for download. Headers already sent or file doesn\'t not exist');
return False;
} else {
$this->addLog('send() and download() methods are available only for files', 'warning');
return False;
}
}