FIX_ISSUE
This commit is contained in:
parent
4fcd101c5f
commit
e5e970386e
@ -947,37 +947,38 @@ if (!function_exists('validateExcelFile')) {
|
||||
|
||||
function validateExcelFile($file)
|
||||
{
|
||||
$allowed = [
|
||||
// Standard Excel Formats
|
||||
'application/vnd.ms-excel', // .xls
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', // .xlsx
|
||||
'application/vnd.oasis.opendocument.spreadsheet', // .ods (OpenDocument)
|
||||
// 1. Check for upload errors first
|
||||
if ($file->getError() !== UPLOAD_ERR_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Macro-Enabled & Specialized Formats
|
||||
'application/vnd.ms-excel.sheet.macroEnabled.12', // .xlsm
|
||||
'application/vnd.ms-excel.template.macroEnabled.12', // .xltm
|
||||
'application/vnd.ms-excel.sheet.binary.macroEnabled.12', // .xlsb
|
||||
'application/vnd.ms-excel.addin.macroEnabled.12', // .xlam
|
||||
// 2. Size check (16MB)
|
||||
if ($file->getSize() > (16 * 1024 * 1024)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Common "Edge Case" and Legacy Types
|
||||
'application/excel', // Legacy
|
||||
'application/x-excel', // Legacy/Vendor
|
||||
'application/x-msexcel', // Legacy/Vendor
|
||||
'application/x-ms-excel', // Legacy/Vendor
|
||||
'application/x-dos_ms_excel', // Very old legacy
|
||||
'text/xls', // Common mislabel
|
||||
'text/xlsx' // Common mislabel
|
||||
$allowedMimeTypes = [
|
||||
'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
|
||||
];
|
||||
|
||||
// if ($file->getError() !== UPLOAD_ERR_OK) return 'Upload error';
|
||||
// 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;
|
||||
$allowedExtensions = ['xls', 'xlsx', 'xlsm', 'xlsb', 'ods'];
|
||||
|
||||
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