diff --git a/packages/actions/src/Concerns/CanImportRecords.php b/packages/actions/src/Concerns/CanImportRecords.php index f3019ccb0f..74e49ee9ea 100644 --- a/packages/actions/src/Concerns/CanImportRecords.php +++ b/packages/actions/src/Concerns/CanImportRecords.php @@ -439,7 +439,21 @@ trait CanImportRecords protected function detectCsvEncoding(mixed $resource): ?string { - $fileHeader = fgets($resource); + rewind($resource); + + $lineCount = 0; + $contentSample = ''; + + while ((! feof($resource)) && ($lineCount < 20)) { + $line = fgets($resource); + + if ($line === false) { + break; + } + + $contentSample .= $line; + $lineCount++; + } // The encoding of a subset should be declared before the encoding of its superset. $encodings = [ @@ -454,7 +468,7 @@ trait CanImportRecords ]; foreach ($encodings as $encoding) { - if (! mb_check_encoding($fileHeader, $encoding)) { + if (! mb_check_encoding($contentSample, $encoding)) { continue; }