Skip to content

Commit

Permalink
Merge pull request #255 from Defcon0/fix-zip-open-issue
Browse files Browse the repository at this point in the history
zip_open() is deprecated in OoxmlConversion
  • Loading branch information
christianbltr authored Nov 15, 2024
2 parents 58c43bc + 8b0d678 commit e0dc0c3
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Classes/Utility/OoxmlConversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,27 @@ public function __construct($filePath)
private function readDocx()
{
$content = '';
$zip = zip_open($this->filename);
$zip = new \ZipArchive();

if (!$zip || is_numeric($zip)) {
if ($zip->open($this->filename) !== true) {
return false;
}

while ($zipEntry = zip_read($zip)) {
if (zip_entry_open($zip, $zipEntry) === false) {
continue;
}
if (zip_entry_name($zipEntry) !== 'word/document.xml') {
for ($i = 0; $i < $zip->numFiles; $i++) {
$zipEntry = $zip->getNameIndex($i);

if ($zipEntry !== 'word/document.xml') {
continue;
}
$content .= zip_entry_read($zipEntry, zip_entry_filesize($zipEntry));
zip_entry_close($zipEntry);

$content .= ($zip->getFromName($zipEntry) ?: '');
}
zip_close($zip);

$zip->close();

$content = str_replace('</w:r></w:p></w:tc><w:tc>', ' ', $content);
$content = str_replace('</w:r></w:p>', "\r\n", $content);

return strip_tags($content);
}

Expand Down

0 comments on commit e0dc0c3

Please sign in to comment.