FIX_ISSUE
This commit is contained in:
parent
4fcd101c5f
commit
e5e970386e
@ -947,37 +947,38 @@ if (!function_exists('validateExcelFile')) {
|
|||||||
|
|
||||||
function validateExcelFile($file)
|
function validateExcelFile($file)
|
||||||
{
|
{
|
||||||
$allowed = [
|
// 1. Check for upload errors first
|
||||||
// Standard Excel Formats
|
if ($file->getError() !== UPLOAD_ERR_OK) {
|
||||||
'application/vnd.ms-excel', // .xls
|
return false;
|
||||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', // .xlsx
|
}
|
||||||
'application/vnd.oasis.opendocument.spreadsheet', // .ods (OpenDocument)
|
|
||||||
|
|
||||||
// Macro-Enabled & Specialized Formats
|
// 2. Size check (16MB)
|
||||||
'application/vnd.ms-excel.sheet.macroEnabled.12', // .xlsm
|
if ($file->getSize() > (16 * 1024 * 1024)) {
|
||||||
'application/vnd.ms-excel.template.macroEnabled.12', // .xltm
|
return false;
|
||||||
'application/vnd.ms-excel.sheet.binary.macroEnabled.12', // .xlsb
|
}
|
||||||
'application/vnd.ms-excel.addin.macroEnabled.12', // .xlam
|
|
||||||
|
|
||||||
// Common "Edge Case" and Legacy Types
|
$allowedMimeTypes = [
|
||||||
'application/excel', // Legacy
|
'application/vnd.ms-excel',
|
||||||
'application/x-excel', // Legacy/Vendor
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||||
'application/x-msexcel', // Legacy/Vendor
|
'application/vnd.oasis.opendocument.spreadsheet',
|
||||||
'application/x-ms-excel', // Legacy/Vendor
|
'application/vnd.ms-excel.sheet.macroEnabled.12',
|
||||||
'application/x-dos_ms_excel', // Very old legacy
|
'application/zip', // Crucial: Many servers see .xlsx as a zip
|
||||||
'text/xls', // Common mislabel
|
'application/octet-stream' // Fallback for some browser transfers
|
||||||
'text/xlsx' // Common mislabel
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// if ($file->getError() !== UPLOAD_ERR_OK) return 'Upload error';
|
$allowedExtensions = ['xls', 'xlsx', 'xlsm', 'xlsb', 'ods'];
|
||||||
// if ($file->getSize() > (16 * 1024 * 1024)) return 'File too large';
|
|
||||||
// if (!in_array($file->getClientMimeType(), $allowed, true)) return 'Invalid file type';
|
|
||||||
|
|
||||||
if ($file->getError() !== UPLOAD_ERR_OK) return false;
|
|
||||||
if ($file->getSize() > (16 * 1024 * 1024)) return false;
|
|
||||||
if (!in_array($file->getClientMimeType(), $allowed, true)) return false;
|
|
||||||
|
|
||||||
return true;
|
// Get file info
|
||||||
|
$mime = $file->getClientMimeType();
|
||||||
|
$extension = strtolower($file->getClientOriginalExtension());
|
||||||
|
|
||||||
|
// 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)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user