PHPePub\Core\EPub::sendBook PHP Method

sendBook() public method

Sending will fail if the output buffer is in use. You can override this limit by calling setIgnoreEmptyBuffer(TRUE), though the function will still fail if that buffer is not empty.
public sendBook ( string $fileName ) : string | boolean
$fileName string The name of the book without the .epub at the end.
return string | boolean The sent file name if successful, FALSE if it failed.
    function sendBook($fileName)
    {
        if (!$this->isFinalized) {
            $this->finalize();
        }
        if (!BinStringStatic::endsWith($fileName, ".epub")) {
            $fileName .= ".epub";
        }
        if (true === $this->zip->sendZip($fileName, "application/epub+zip")) {
            return $fileName;
        }
        return false;
    }

Usage Example

Beispiel #1
0
$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->sendBook("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.
All Usage Examples Of PHPePub\Core\EPub::sendBook