Skip to content

Commit e72a269

Browse files
committed
Handle zips with Windoze directory separators (\) rather than the standard linux (/)
1 parent 6f60191 commit e72a269

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/PhpSpreadsheet/Reader/Xlsx.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,18 @@ private function getFromZipArchive(ZipArchive $archive, $fileName = '')
403403
// Sadly, some 3rd party xlsx generators don't use consistent case for filenaming
404404
// so we need to load case-insensitively from the zip file
405405

406-
// Apache POI fixes
407406
$contents = $archive->getFromName($fileName, 0, ZipArchive::FL_NOCASE);
407+
408+
// Apache POI fixes
408409
if ($contents === false) {
409410
$contents = $archive->getFromName(substr($fileName, 1), 0, ZipArchive::FL_NOCASE);
410411
}
411412

413+
// Has the file been saved with Windoze directory separators rather than unix?
414+
if ($contents === false) {
415+
$contents = $archive->getFromName(str_replace('/', '\\', $fileName), 0, ZipArchive::FL_NOCASE);
416+
}
417+
412418
return ($contents === false) ? '' : $contents;
413419
}
414420

src/PhpSpreadsheet/Shared/File.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ public static function assertFile(string $filename, string $zipMember = ''): voi
156156
if ($zipMember !== '') {
157157
$zipfile = "zip://$filename#$zipMember";
158158
if (!self::fileExists($zipfile)) {
159-
throw new ReaderException("Could not find zip member $zipfile");
159+
// Has the file been saved with Windoze directory separators rather than unix?
160+
$zipfile = "zip://$filename#" . str_replace('/', '\\', $zipMember);
161+
if (!self::fileExists($zipfile)) {
162+
throw new ReaderException("Could not find zip member $zipfile");
163+
}
160164
}
161165
}
162166
}

0 commit comments

Comments
 (0)