Reputation: 23
I'm trying to open Epub file from my own server.
PHP:
<?php
$filename = '../files/2.epub';
header('Content-type: application/epub+zip');
header("Content-Disposition:inline;filename='somefilename.epub'");
//header('Content-Transfer-Encoding: binary');
readfile($filename);
?>
Javascript:
<script>
var Book = ePub("http://localhost/epub/examples/file.php");
Book.renderTo("area");
</script>
ERROR occured:
Navigated to http://localhost/epub/examples/basic.html
core.js:120 GET http://localhost/epub/examples/file.phpMETA- INF/container.xml 404 (Not Found)EPUBJS.core.request @ core.js:120EPUBJS.Book.loadXml @ book.js:586EPUBJS.Book.loadPackage @ book.js:188EPUBJS.Book.open @ book.js:148EPUBJS.Book @ book.js:115root.ePub @ base.js:48(anonymous function) @ basic.html:95
book.js:204 Could not load book at: META-INF/container.xml(anonymous func tion) @ book.js:204lib$rsvp$$internal$$tryCatch @ rsvp.js:493lib$rsvp$$internal$$invokeCallback @ rsvp.js:505lib$rsvp$$internal$$publish @ rsvp.js:476lib$rsvp$$internal$$publishRejection @ rsvp.js:419lib$rsvp$asap$$flush @ rsvp.js:1198
book.js:1357 Object {message: null, stack: "Error↵ at XMLHttpRequest.handler (http://localhost/epub/build/epub.js:3493:13)"}
It works when I use the url directed to the file like this this:
var Book = ePub("http://localhost/epub/files/1.epub");
My goal is to view epub file but before that, I need to validate whether the user can view the epub.
I use this plugin for viewing. https://github.com/futurepress/epub.js
I'm using angularJS. In the future, I will be saving it in the indexedDB or Web SQL for local viewing.
Thanks in advance!
Upvotes: 2
Views: 912
Reputation: 182
More a workaround than an actual solution. For some reason if the url does not end with .epub, epubjs does something different in the handling.
My original url is:
http://localhost/api.php?getbook=true&externalbookid=a13a9cef-1f83-4695-8cbf-1c0aafbf958e
In JS:
var book = ePub("http://localhost/file.epub?bookexternalid=5090a553-aa97-44a7-85cc-94ad07a6dc44");
I went with htaccess:
RewriteEngine On
RewriteRule file.epub/?$ /api.php?getbook=true&%{QUERY_STRING} [R=301,NC,L]
This should fix your problem.
Upvotes: 0