Fix: Better detection of charset of .csv file

This commit is contained in:
Manuel
2025-03-26 15:10:57 +01:00
parent fed5c56ae7
commit 1f7f12db7e
@@ -439,7 +439,8 @@ trait CanImportRecords
protected function detectCsvEncoding(mixed $resource): ?string
{
$fileHeader = fgets($resource);
rewind($resource);
$contentSample = fread($resource, 8192);
// The encoding of a subset should be declared before the encoding of its superset.
$encodings = [
@@ -454,7 +455,7 @@ trait CanImportRecords
];
foreach ($encodings as $encoding) {
if (! mb_check_encoding($fileHeader, $encoding)) {
if (! mb_check_encoding($contentSample, $encoding)) {
continue;
}