예제 #1
0
<?php

require_once "common.php";
// Search for book
$id = intval($_REQUEST["id"]);
$book = mqone("SELECT * FROM books WHERE id={$id};");
if (!$book) {
    header("Location: /booklist.php?error=" . urlencode(_("The requested book has not been found")));
    exit;
}
$attr = @json_decode($book["attribs"], true);
$format = trim($_REQUEST["format"]);
// Now search for the requested file
if (!isset($attr["formats"][$format])) {
    header("Location: /booklist.php?error=" . urlencode(sprintf(_("This book's requested format (%s) is not available."), $format)));
    exit;
}
$amime = array("epub" => "application/epub+zip", "mobi" => "application/mobi", "pdf" => "application/pdf");
$file = UPLOAD_ROOT . "/" . $attr["formats"][$format]["name"];
header("Content-Type: " . $amime[$format]);
header("Content-Length: " . $attr["formats"][$format]["size"]);
header("Content-Disposition: attachment; filename=\"" . good_filename($book["title"], $book["authors"]) . "." . $format . "\"");
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
readfile($file);
예제 #2
0
</td>
	<td><?php 
    if ($c["downloadable"]) {
        echo "<img src=\"/assets/img/download.png\"/>";
        $formats = array("epub", "mobi", "pdf");
        foreach ($formats as $format) {
            if ($attribs["formats"][$format]["othercollection"]) {
                // other collection than the original one ?
                $two = "2";
                $description = sprintf(_("Download EPUB version of this ebook IN ANOTHER COLLECTION (%sKB)"), intval($attribs["formats"][$format]["size"] / 102.4) / 10);
            } else {
                $two = "";
                $description = sprintf(_("Download EPUB version of this ebook (%sKB)"), intval($attribs["formats"][$format]["size"] / 102.4) / 10);
            }
            if (isset($attribs["formats"][$format])) {
                echo "<a href=\"/download/" . $c["id"] . "/" . $format . "/" . urlencode(good_filename($c["title"], $c["authors"])) . "." . $format . "\">";
                echo "<img src=\"/assets/img/epub" . $two . ".png\" alt=\"" . $description . "\" title=\"" . $description . "\" />";
                echo "</a>";
            }
        }
    } else {
        if ($c["uid"]) {
            // Moderating ...
            echo "<img src=\"/assets/img/almost.png\" title=\"" . _("We have a file in the moderation queue for this book") . "\" alt=\"" . _("We have a file in the moderation queue for this book") . "\" />";
        } else {
            echo "<img src=\"/assets/img/delete.png\" title=\"" . _("We don't have it yet") . "\" alt=\"" . _("We don't have it yet") . "\" />";
        }
    }
    ?>
</td>
<td>