From 5dd1964f25481536ce21a41fecbf614cc18a1d31 Mon Sep 17 00:00:00 2001 From: "venkatesh.r" Date: Tue, 3 Feb 2026 13:09:38 +0530 Subject: [PATCH] FIX_ISSUE --- app/Helpers/utility_helper.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/app/Helpers/utility_helper.php b/app/Helpers/utility_helper.php index 3d153d75..178ec18a 100755 --- a/app/Helpers/utility_helper.php +++ b/app/Helpers/utility_helper.php @@ -947,34 +947,33 @@ if (!function_exists('validateExcelFile')) { function validateExcelFile($file) { - // 1. Check for upload errors first - if ($file->getError() !== UPLOAD_ERR_OK) { + // 1. Check if the file was uploaded without errors + if (! $file->isValid() || $file->hasMoved()) { return false; } // 2. Size check (16MB) - if ($file->getSize() > (16 * 1024 * 1024)) { + if ($file->getSizeByUnit('mb') > 16) { return false; } - $allowedMimeTypes = [ + // 3. Define allowed types + $allowedMimes = [ 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.oasis.opendocument.spreadsheet', - 'application/vnd.ms-excel.sheet.macroEnabled.12', - 'application/zip', // Crucial: Many servers see .xlsx as a zip - 'application/octet-stream' // Fallback for some browser transfers + 'application/zip', + 'application/octet-stream' ]; - $allowedExtensions = ['xls', 'xlsx', 'xlsm', 'xlsb', 'ods']; + $allowedExtensions = ['xls', 'xlsx', 'ods', 'xlsm']; - // Get file info + // Get the actual values using CI4 methods $mime = $file->getClientMimeType(); - $extension = strtolower($file->getClientOriginalExtension()); + $extension = $file->getExtension(); // This is the CI4 method - // 3. Dual Validation: Check if EITHER the mime is in our list OR the extension is valid - // This solves issues where the server/browser misidentifies the MIME type. - if (in_array($mime, $allowedMimeTypes, true) || in_array($extension, $allowedExtensions, true)) { + // 4. Validate + if (in_array($mime, $allowedMimes) || in_array($extension, $allowedExtensions)) { return true; }