From 1657ae82916aacbea238530fcb4a42f13e5ec2e7 Mon Sep 17 00:00:00 2001 From: Paolo Date: Mon, 29 Sep 2025 09:32:21 +0200 Subject: [PATCH] - Removed global function uploadFile from application/helpers/hlp_common_helper.php - Added new protected method uploadFile to application/core/FHC_Controller.php - Replaced global function uploadFile with the protected method FHC_Controller->uploadFile --- application/core/FHC_Controller.php | 23 +++++++++++++++++++++++ application/core/Notiz_Controller.php | 4 ++-- application/helpers/hlp_common_helper.php | 22 ---------------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/application/core/FHC_Controller.php b/application/core/FHC_Controller.php index fe0ca00e4..91d73c77f 100644 --- a/application/core/FHC_Controller.php +++ b/application/core/FHC_Controller.php @@ -218,6 +218,29 @@ abstract class FHC_Controller extends CI_Controller return json_decode($this->input->raw_input_stream); } + /** + * Utility function to upload a file + * - post_field_name: the name of the field in the HTTP POST payload, this is also the index in the super global $_FILES array + * - allowed_types: a list of file extensions that are allowed to be uploaded (ex. array('pdf', 'odt') or array('jpg', 'jpeg', 'gif') + */ + protected function uploadFile($post_field_name, $allowed_types = array('*')) + { + $this->load->library( + 'upload', + array( + 'upload_path' => sys_get_temp_dir(), + 'allowed_types' => $allowed_types, + 'overwrite' => true + ) + ); + + // If the upload was a success then return the uploaded file info + if ($this->upload->do_upload($post_field_name)) return success($this->upload->data()); + + // If an error occurred then return it without tags + return error($this->upload->display_errors('', '')); + } + //------------------------------------------------------------------------------------------------------------------ // Private methods diff --git a/application/core/Notiz_Controller.php b/application/core/Notiz_Controller.php index 42a5dd3c7..9ba350949 100644 --- a/application/core/Notiz_Controller.php +++ b/application/core/Notiz_Controller.php @@ -206,7 +206,7 @@ abstract class Notiz_Controller extends FHCAPI_Controller //Todo(manu) check if filetypes weiter eingeschränkt werden sollen //Todo(manu)check name files: nicht gleiches file 2mal hochladen //Todo define in dms component: readFile, downloadFile - $uploadDataResult = uploadFile($k); + $uploadDataResult = $this->uploadFile($k); if (isError($uploadDataResult)) { $this->db->trans_rollback(); @@ -350,7 +350,7 @@ abstract class Notiz_Controller extends FHCAPI_Controller //Todo(manu) check if filetypes weiter eingeschränkt werden sollen //Todo(manu)check name files: nicht gleiches file 2mal hochladen //Todo define in dms component: readFile, downloadFile - $uploadDataResult = uploadFile($k); + $uploadDataResult = $this->uploadFile($k); if (isError($uploadDataResult)) { $this->db->trans_rollback(); diff --git a/application/helpers/hlp_common_helper.php b/application/helpers/hlp_common_helper.php index 0f547adad..654d563f0 100644 --- a/application/helpers/hlp_common_helper.php +++ b/application/helpers/hlp_common_helper.php @@ -423,28 +423,6 @@ function isValidDate($dateString) } } -/** - * Utility function to upload a file - */ -function uploadFile($post_field_name, $allowed_types = array('*')) -{ - $ci =& get_instance(); // get CI instance - $ci->load->library( - 'upload', - array( - 'upload_path' => sys_get_temp_dir(), - 'allowed_types' => $allowed_types, - 'overwrite' => true - ) - ); - - // If the upload was a success then return the uploaded file info - if ($ci->upload->do_upload($post_field_name)) return success($ci->upload->data()); - - // If an error occurred then return it - return error($ci->upload->display_errors('', '')); -} - // ------------------------------------------------------------------------ // PHP functions that don't exist in older versions // ------------------------------------------------------------------------