public function output($mode, $filename = '')
{
switch ($mode) {
case self::MODE_DOWNLOAD:
if (!headers_sent()) {
$result = $this->_render();
header("Content-Description: File Transfer");
header("Cache-Control: public; must-revalidate, max-age=0");
// HTTP/1.1
header("Pragme: public");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
// Date in the past
header("Last-Modified: " . gmdate('D, d m Y H:i:s') . " GMT");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream", false);
header("Content-Type: application/download", false);
header("Content-Type: application/pdf", false);
header('Content-Disposition: attachment; filename="' . basename($filename) . '";');
header("Content-Transfer-Encoding: binary");
header("Content-Length:" . strlen($result));
echo $result;
$this->_deleteFile();
exit;
} else {
throw new Exception("Headers already sent");
}
break;
case self::MODE_STRING:
return $this->_render();
break;
case self::MODE_EMBEDDED:
if (!headers_sent()) {
$result = $this->_render();
header("Content-type: application/pdf");
header("Cache-control: public, must-revalidate, max-age=0");
// HTTP/1.1
header("Pragme: public");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
// Date in the past
header("Last-Modified: " . gmdate('D, d m Y H:i:s') . " GMT");
header("Content-Length: " . strlen($result));
header('Content-Disposition: inline; filename="' . basename($filename) . '";');
echo $result;
$this->_deleteFile();
exit;
} else {
throw new Exception("Headers already sent");
}
break;
case self::MODE_SAVE:
file_put_contents($filename, $this->_render());
$this->_deleteFile();
break;
default:
throw new Exception("Mode: " . $mode . " is not supported");
}
return TRUE;
}