FIX_ISSUE
This commit is contained in:
parent
e5e970386e
commit
5dd1964f25
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user