add function sendFile()

This commit is contained in:
Uwe Steinmann 2018-01-18 08:48:32 +01:00
parent f71aab5921
commit ccb56e827c

View File

@ -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);
}
} /* }}} */
?>