Adapted DMSLib download method to be more generic

DMSLib now extends FHC Controller to use its new method 'outputFile',
which sets HTTP headers and reads the file.
DMSLib uses now download function to accept params from Controller like
own filename or special disposition.
Loading document and retrieving file info is outsourced into own method
to be reusable.

Signed-off-by: cris-technikum <hainberg@technikum-wien.at>
This commit is contained in:
Cris
2021-04-21 17:38:07 +02:00
committed by cris-technikum
parent 731c5b9461
commit 6dcb5e3a65
2 changed files with 112 additions and 33 deletions
+26
View File
@@ -132,6 +132,32 @@ abstract class FHC_Controller extends CI_Controller
{
$this->output->set_content_type('application/json')->set_output(json_encode($mixed));
}
protected function outputFile($fileObj)
{
if (file_exists($fileObj->file))
{
$finfo = new finfo(FILEINFO_MIME);
header('Content-Description: File Transfer');
header('Content-Type: '. $finfo->file($fileObj->file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($fileObj->file));
if (isset($fileObj->disposition) && ($fileObj->disposition == 'inline' || $fileObj->disposition == 'attachment'))
{
header('Content-Disposition: '. $fileObj->disposition. '; filename="'. $fileObj->name. '"');
}
readfile($fileObj->file);
exit;
}
return false;
}
//------------------------------------------------------------------------------------------------------------------
// Private methods