PHP ZipArchive :: close返回false

I'm trying to change some docx variables from PHP. But on save step always got false.

I tried to 777 permissions to directory, php-zip extension, "ext-zip": "*" in composer.json.

My code:

$zip = new \ZipArchive();

        $wordDoc = $this->container->get('kernel')->getRootDir() . '/../file.docx';
        $fileToModify = 'word/document.xml';

        if ($zip->open($wordDoc, ZipArchive::CREATE) === TRUE) {
            $oldContents = $zip->getFromName($fileToModify);

            $newContents = str_replace(' MERGEFIELD __FIRSTNAME__ ', 'NEWNAME', $oldContents);

            $zip->deleteName($fileToModify);

            $zip->addFromString($fileToModify, $newContents);

            if ($zip->close()) {
                echo "Done.";
            }
            else {
                echo 'fail';exit();
            }
        }

php -m zip enabled:

zip,
zlib

php --ini zip enabled:

/etc/php7/conf.d/00_zip.ini,

I expect overwrite old file and get new with new values but always got false on $zip->close();

Solved. Before working needs to create a copy of origin file.

$original = $this->container->get('kernel')->getRootDir() . '/../file.docx';
if (copy($original, $this->container->get('kernel')->getRootDir() . '/../temp/newFile.docx')) {
      $tempFile = $this->container->get('kernel')->getRootDir() . '/../temp/newFile.docx';
}