FIX_ISSUE
This commit is contained in:
parent
e5e970386e
commit
5dd1964f25
@ -947,34 +947,33 @@ if (!function_exists('validateExcelFile')) {
|
|||||||
|
|
||||||
function validateExcelFile($file)
|
function validateExcelFile($file)
|
||||||
{
|
{
|
||||||
// 1. Check for upload errors first
|
// 1. Check if the file was uploaded without errors
|
||||||
if ($file->getError() !== UPLOAD_ERR_OK) {
|
if (! $file->isValid() || $file->hasMoved()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Size check (16MB)
|
// 2. Size check (16MB)
|
||||||
if ($file->getSize() > (16 * 1024 * 1024)) {
|
if ($file->getSizeByUnit('mb') > 16) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$allowedMimeTypes = [
|
// 3. Define allowed types
|
||||||
|
$allowedMimes = [
|
||||||
'application/vnd.ms-excel',
|
'application/vnd.ms-excel',
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||||
'application/vnd.oasis.opendocument.spreadsheet',
|
'application/vnd.oasis.opendocument.spreadsheet',
|
||||||
'application/vnd.ms-excel.sheet.macroEnabled.12',
|
'application/zip',
|
||||||
'application/zip', // Crucial: Many servers see .xlsx as a zip
|
'application/octet-stream'
|
||||||
'application/octet-stream' // Fallback for some browser transfers
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$allowedExtensions = ['xls', 'xlsx', 'xlsm', 'xlsb', 'ods'];
|
$allowedExtensions = ['xls', 'xlsx', 'ods', 'xlsm'];
|
||||||
|
|
||||||
// Get file info
|
// Get the actual values using CI4 methods
|
||||||
$mime = $file->getClientMimeType();
|
$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
|
// 4. Validate
|
||||||
// This solves issues where the server/browser misidentifies the MIME type.
|
if (in_array($mime, $allowedMimes) || in_array($extension, $allowedExtensions)) {
|
||||||
if (in_array($mime, $allowedMimeTypes, true) || in_array($extension, $allowedExtensions, true)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user