I'm looking at a tutorial for creating an ePub file. It states that the zip that contains the ePub book must contain a textfile called mimetype that "must be first in the zip file, uncompressed". The example he gives uses a commandline tool, I was wondering how I could do the same thing in PHP.
I assume it would be first in the zip file as long as its the first thing I add in the code, but how to add it to the zip uncompressed. Or am I misreading this?
Thanks in advance.
It seems the base64-encoded file above is a little buggy (ZipArchive refused to open it), but the following works:
// make the archive first
file_put_contents($fileName, base64_decode("UEsDBAoAAAAAAOmRAT1vYassFAAAABQAAAAIAAAAbWltZXR5cGVhcHBsaWNhdGlvbi9lcHViK3ppcFBLAQIUAAoAAAAAAOmRAT1vYassFAAAABQAAAAIAAAAAAAAAAAAIAAAAAAAAABtaW1ldHlwZVBLBQYAAAAAAQABADYAAAA6AAAAAAA="));
// open archive
if (($err = $zipfile->open($fileName)) !== TRUE) {
trigger_error("Could not open archive: " . $fileName, E_USER_ERROR);
}
$zipfile->add(...)
I tested this with my own epub-generating code and it worked fine. Epubcheck 1.05 validates it. By the way, if you're using "OPL's EPUB library", beware that it's quite buggy. I will probably post a fix to it soon with this solution baked in, but beware till then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With