From ccb56e827ca887829f7a929e5e2f718df576c197 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 18 Jan 2018 08:48:32 +0100 Subject: [PATCH] add function sendFile() --- inc/inc.Utils.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/inc/inc.Utils.php b/inc/inc.Utils.php index 327cdbf3f..1532ea793 100644 --- a/inc/inc.Utils.php +++ b/inc/inc.Utils.php @@ -586,4 +586,24 @@ function addDirSep($str) { /* {{{ */ else return trim($str); } /* }}} */ + +/** + * Send a file from disk to the browser + * + * This function uses either readfile() or the xѕendfile apache module if + * it is installed. + * + * @param string $filename + */ +function sendFile($filename) { /* {{{ */ + if(function_exists('apache_get_modules') && in_array('mod_xsendfile',apache_get_modules())) { + header("X-Sendfile: ".$filename); + } else { + /* Make sure output buffering is off */ + if (ob_get_level()) { + ob_end_clean(); + } + readfile($filename); + } +} /* }}} */ ?>