Example #1
0
fwrite($fp, "application/epub+zip");
fclose($fp);
// Create & populate container.xml file
$container_filename = $temp_epub_dir_name . DIRECTORY_SEPARATOR . "META-INF" . DIRECTORY_SEPARATOR . "container.xml";
$fp = fopen($container_filename, "w") or die("Couldn't open temporary file for epub archive (container.xml)");
$container_file_contents = '<?xml version="1.0"?>';
$container_file_contents .= '<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">';
$container_file_contents .= '<rootfiles>';
$container_file_contents .= '<rootfile full-path="OEBPS/book.opf" media-type="application/oebps-package+xml"/>';
$container_file_contents .= '</rootfiles>';
$container_file_contents .= '</container>';
fwrite($fp, $container_file_contents);
fclose($fp);
// Load intermediate TEI file
$tei_data = new TeiDom($_POST);
$teiDom = $tei_data->getTeiDom();
// echo $tei_data->getTeiString(); die();
// Get all images referenced in tei & copy over to image directory
// DOM Query using xpath: http://www.exforsys.com/tutorials/php-oracle/querying-a-dom-document-with-xpath.html
$xpath = new DOMXPath($teiDom);
$xpath->registerNamespace('tei', TEI);
$xpath->registerNamespace('html', HTML);
$xpath->registerNamespace('anth', ANTH);
$query = '//img/@src';
$image_url_nodes = $xpath->query($query);
foreach ($image_url_nodes as $image_url_node) {
    // Get image url & open file
    $image_url = $image_url_node->nodeValue;
    $image_filename = preg_replace('/^.*\\//', '', $image_url);
    // Erase all but filename from URL
    $ch = curl_init($image_url);