Added logic to download and open a document

Signed-off-by: cris-technikum <hainberg@technikum-wien.at>
This commit is contained in:
Cris
2021-01-14 14:13:17 +01:00
committed by cris-technikum
parent 5af134312c
commit b57a3ec90f
2 changed files with 55 additions and 0 deletions
@@ -191,6 +191,20 @@ class requestAnrechnung extends Auth_Controller
}
}
/**
* Download and open uploaded document (Nachweisdokument).
*/
public function download()
{
$dms_id = $this->input->get('dms_id');
if (!is_numeric($dms_id))
{
show_error('Wrong parameter');
}
$this->dmslib->download($dms_id);
}
/**
* Retrieve the UID of the logged user and checks if it is valid
+41
View File
@@ -132,6 +132,47 @@ class DmsLib
// return result of uploaded data
return success($upload_data); // data about the uploaded file
}
/**
* Download a document
* @param $dms_id
*/
public function download($dms_id)
{
if (!is_numeric($dms_id))
{
show_error('Wrong parameter');
}
$this->ci->DmsVersionModel->addSelect('filename');
$result = $this->ci->DmsVersionModel->loadWhere(array('dms_id' => $dms_id));
if (isError($result))
{
show_error(getError($result));
}
$filename = $result->retval[0]->filename;
$file = DMS_PATH. $filename;
if (file_exists($file))
{
$finfo = new finfo(FILEINFO_MIME);
header('Content-Description: File Transfer');
header('Content-Type: '.$finfo->file($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
else
{
show_error('File does not exist');
}
}
/**
* Saves a Document