PHPePub\Core\EPub::saveBook PHP Method

saveBook() public method

Save the ePub file to local disk.
public saveBook ( string $fileName, string $baseDir = '.' ) : string
$fileName string
$baseDir string If empty baseDir is absolute to server path, if omitted it's relative to script path
return string The sent file name if successful, FALSE if it failed.
    function saveBook($fileName, $baseDir = '.')
    {
        // Make fileName safe
        // $fileName = self::sanitizeFileName($fileName); // It is up to the user to ensure valid file names.
        // Finalize book, if it's not done already
        if (!$this->isFinalized) {
            $this->finalize();
        }
        if (!BinStringStatic::endsWith($fileName, ".epub")) {
            $fileName .= ".epub";
        }
        // Try to open file access
        $fh = fopen($baseDir . '/' . $fileName, "w");
        if ($fh) {
            fputs($fh, $this->getBook());
            fclose($fh);
            // if file is written return TRUE
            return $fileName;
        }
        // return FALSE by default
        return false;
    }

Usage Example

 /**
  * @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()));
 }
All Usage Examples Of PHPePub\Core\EPub::saveBook