/**
* Save PhpPresentation to file
*
* @param string $pFilename
* @throws \Exception
*/
public function save($pFilename)
{
if (empty($pFilename)) {
throw new \Exception("Filename is empty.");
}
if (!is_null($this->presentation)) {
// Create new ZIP file and open it for writing
$objZip = new \ZipArchive();
// Try opening the ZIP file
if ($objZip->open($pFilename, \ZipArchive::CREATE) !== true) {
if ($objZip->open($pFilename, \ZipArchive::OVERWRITE) !== true) {
throw new \Exception("Could not open " . $pFilename . " for writing.");
}
}
// Add media
$slideCount = $this->presentation->getSlideCount();
for ($i = 0; $i < $slideCount; ++$i) {
for ($j = 0; $j < $this->presentation->getSlide($i)->getShapeCollection()->count(); ++$j) {
if ($this->presentation->getSlide($i)->getShapeCollection()->offsetGet($j) instanceof AbstractDrawing) {
$imgTemp = $this->presentation->getSlide($i)->getShapeCollection()->offsetGet($j);
$objZip->addFromString('media/' . $imgTemp->getFilename(), file_get_contents($imgTemp->getPath()));
}
}
}
// Add PhpPresentation.xml to the document, which represents a PHP serialized PhpPresentation object
$objZip->addFromString('PhpPresentation.xml', $this->writeSerialized($this->presentation, $pFilename));
// Close file
if ($objZip->close() === false) {
throw new \Exception("Could not close zip file {$pFilename}.");
}
} else {
throw new \Exception("PhpPresentation object unassigned.");
}
}