setPhpWord($phpWord); // Create parts $this->parts = array( 'Mimetype' => 'mimetype', 'Content' => 'content.xml', 'Meta' => 'meta.xml', 'Styles' => 'styles.xml', 'Manifest' => 'META-INF/manifest.xml', ); foreach (array_keys($this->parts) as $partName) { $partClass = get_class($this) . '\\Part\\' . $partName; if (class_exists($partClass)) { $partObject = new $partClass(); $partObject->setParentWriter($this); $this->writerParts[strtolower($partName)] = $partObject; } } // Set package paths $this->mediaPaths = array('image' => 'Pictures/'); } /** * Save PhpWord to file * * @param string $filename * @throws \PhpOffice\PhpWord\Exception\Exception */ public function save($filename = null) { $filename = $this->getTempFile($filename); $objZip = $this->getZipArchive($filename); // Add section media files $sectionMedia = Media::getElements('section'); if (!empty($sectionMedia)) { $this->addFilesToPackage($objZip, $sectionMedia); } // Write parts foreach ($this->parts as $partName => $fileName) { if ($fileName != '') { $objZip->addFromString($fileName, $this->getWriterPart($partName)->write()); } } // Close file if ($objZip->close() === false) { throw new Exception("Could not close zip file $filename."); } $this->cleanupTempFile(); } }