Post by code on Oct 16, 2021 4:45:26 GMT
Hi,
I keep it short....
(this is only for the intrested)
The php file produces online an e-book(file.epub)
Intresting in the code is that you can zip in php.
Here a link to my website:
booktest.byethost24.com/test2.php
Here the php code:
To open the file.epub with a epub reader:
www.epubfilereader.com
It gives probally one error popup...but then runs after it.
Goodluck,
code
I keep it short....
(this is only for the intrested)
The php file produces online an e-book(file.epub)
Intresting in the code is that you can zip in php.
Here a link to my website:
booktest.byethost24.com/test2.php
Here the php code:
<?
$af= fopen("container.xml", "w+");
$txt5 =$txt5."<?xml version='1.0' encoding='UTF-8'?>";
$txt5 =$txt5."<container xmlns='urn:oasis:names:tc:opendocument:xmlns:container' version='1.0'>";
$txt5 =$txt5."<rootfiles>";
$txt5 =$txt5."<rootfile media-type='application/oebps-package+xml' full-path='OEBPS/book.opf'/>";
$txt5 =$txt5."</rootfiles>";
$txt5 =$txt5."</container>";
fwrite($af, $txt5);
fclose($af);
$af= fopen("book.ncx", "w+");
$txt3 =$txt3."<?xml version='1.0' encoding='utf-8'?>";
$txt3 =$txt3."<ncx version='2005-1' xml:lang='en' xmlns='http://www.daisy.org/z3986/2005/ncx/'>";
$txt3 =$txt3." <head>";
$txt3 =$txt3." <meta name='dtb:uid' content='abcdef' />";
$txt3 =$txt3." <meta name='dtb:depth' content='1' />";
$txt3 =$txt3." <meta name='dtb:totalPageCount' content='0' />";
$txt3 =$txt3." <meta name='dtb:maxPageNumber' content='0' />";
$txt3 =$txt3." </head>";
$txt3 =$txt3."";
$txt3 =$txt3."<docTitle>";
$txt3 =$txt3."<text>Title is...</text>";
$txt3 =$txt3."</docTitle>";
$txt3 =$txt3."<navMap>";
$txt3 =$txt3."<navPoint id='chapter01' playOrder=1 >";
$txt3 =$txt3."<navLabel><text>Chapter 1</text></navLabel>";
$txt3 =$txt3."<content src='chapter01.xhtml' />";
$txt3 =$txt3."</navPoint>";
$txt3="<navPoint id='chapter02' playOrder=1 >";
$txt3 =$txt3."<navLabel><text>Chapter 2</text></navLabel>";
$txt3 =$txt3."<content src='chapter02.xhtml' />";
$txt3 =$txt3."</navPoint>";
$txt3 =$txt3."</navMap>";
$txt3 =$txt3."</ncx>";
fwrite($af, $txt3);
fclose($af);
$af= fopen("book.opf", "w+");
$txt2 =$txt2."";
$txt2 =$txt2."<?xml version='1.0' encoding='utf-8'?>";
$txt2 =$txt2."<package version='2.0' xmlns='http://www.idpf.org/2007/opf' unique-identifier='abcdef'>";
$txt2 =$txt2."<metadata xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:opf='http://www.idpf.org/2007/opf' >";
$txt2 =$txt2." <dc:title>Title is ....</dc:title>";
$txt2 =$txt2." <dc:creator opf:role='aut'>not set</dc:creator>";
$txt2 =$txt2." <dc:language>en-US</dc:language>";
$txt2 =$txt2." <dc:identifier id='abcdef' >abcdef</dc:identifier>";
$txt2 =$txt2." </metadata>";
$txt2 =$txt2."<manifest>";
$txt2 =$txt2."<item id='chapter01' href='chapter01.xhtml' />";
$txt2 =$txt2."<item id='ncx' href='book.ncx' />";
$txt2 =$txt2."<item id='chapter02' href='chapter02.xhtml' />";
$txt2 =$txt2."<item id='ncx' href='book.ncx' />";
$txt2 =$txt2."</manifest>";
$txt2 =$txt2."<spine toc='ncx'>";
$txt2 =$txt2."<itemref idref='chapter01' />";
$txt2 =$txt2."<itemref idref='chapter02' />";
$txt2 =$txt2."</spine>";
$txt2 =$txt2."</package>";
fwrite($af, $txt2);
fclose($af);
$af= fopen("chapter01.xhtml", "w+");
$txt8 =$txt8."";
$txt8 =$txt8."<?xml version='1.0' encoding='utf-8'?>";
$txt8 =$txt8."<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>";
$txt8 =$txt8."<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>";
$txt8 =$txt8." <head>";
$txt8 =$txt8." <meta http-equiv='Content-Type' content='application/xhtml+xml; charset=utf-8' />";
$txt8 =$txt8." <title>Justbasic...</title>";
$txt8 =$txt8." </head>";
$txt8 =$txt8." <body>";
$txt8 =$txt8." <h1>Justbasic...</h1><p><a href='http://www.justbasic.com'>link</a></p>";
$txt8 =$txt8." <h1>Just now...</h1><p><a href='http://google.nl'>link</a></p>";
fwrite($af, $txt8);
fclose($af);
$af= fopen("chapter02.xhtml", "w+");
$txt18 =$txt18."";
$txt18 =$txt18."<?xml version='1.0' encoding='utf-8'?>";
$txt18 =$txt18."<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>";
$txt18 =$txt18."<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>";
$txt18 =$txt18." <head>";
$txt18 =$txt18." <meta http-equiv='Content-Type' content='application/xhtml+xml; charset=utf-8' />";
$txt18 =$txt18." <title>Test</title>";
$txt18 =$txt18." </head>";
$txt18 =$txt18." <body>";
$txt18 =$txt18." <h1>Chapter 2 ...</h1><p><a href='http://www.duckduckgo.nl'>link</a></p>";
$txt18 =$txt18." <h1>Hi...</h1><p><a href='http://google.nl'>link</a></p>";
fwrite($af, $txt18);
fclose($af);
$zip = new ZipArchive();
$zip->open('file.epub', ZipArchive::CREATE | ZipArchive::OVERWRITE);
$zip->addEmptyDir('META-INF');
$zip->addEmptyDir('OEBPS');
$zip->addFromString("mimetype" ,"application/epub+zip");
$zip->addFromString("META-INF/container.xml" ,$txt5);
$zip->addFromString("OEBPS/book.ncx" , $txt3);
$zip->addFromString("OEBPS/book.opf" , $txt2);
$zip->addFromString("OEBPS/chapter01.xhtml" , $txt8);
$zip->addFromString("OEBPS/chapter02.xhtml" , $txt18);
$zip->close();
$txt="";
$txt2="";
$txt3="";
$txt5="";
$txt8="";
$txt18="";
echo "Done...";
echo "<br><a href='/file.epub'>file.epub</a>";
?>
To open the file.epub with a epub reader:
www.epubfilereader.com
It gives probally one error popup...but then runs after it.
Goodluck,
code