/** * @param null|string $filename * @return void */ public function save($filename = null) { if (is_null($filename)) { $filename = time() . Random::getRandStr(32); } $this->filename = $filename; $this->epub->finalize(); $this->epub->saveBook($filename, storage_path($this->getPath())); }
$book->rootLevel(); // $log->logLine("Add TOC"); // $book->buildTOC(); $book->addChapter("Log", "Log.html", $content_start . $log->getLog() . "\n</pre>" . $bookEnd); if ($book->isLogging) { // Only used in case we need to debug EPub.php. $epuplog = $book->getLog(); $book->addChapter("ePubLog", "ePubLog.html", $content_start . $epuplog . "\n</pre>" . $bookEnd); } $book->finalize(); // Finalize the book, and build the archive. // This is not really a part of the EPub class, but IF you have errors and want to know about them, // they would have been written to the output buffer, preventing the book from being sent. // This behaviour is desired as the book will then most likely be corrupt. // However you might want to dump the output to a log, this example section can do that: /* if (ob_get_contents() !== false && ob_get_contents() != '') { $f = fopen ('./log.txt', 'a') or die("Unable to open log.txt."); fwrite($f, "\r\n" . date("D, d M Y H:i:s T") . ": Error in " . __FILE__ . ": \r\n"); fwrite($f, ob_get_contents() . "\r\n"); fclose($f); } */ // Save book as a file relative to your script (for local ePub generation) // Notice that the extension .epub will be added by the script. // The second parameter is a directory name which is '.' by default. Don't use trailing slash! //$book->saveBook('epub-filename', '.'); // Send the book to the client. ".epub" will be appended if missing. $zipData = $book->saveBook("ExampleBook1"); // After this point your script should call exit. If anything is written to the output, // it'll be appended to the end of the book, causing the epub file to become corrupt.