getInt('id'); $db = new PDO('sqlite:' . Config::get(Config::CALIBRE_DB)); $sth = $db->prepare("SELECT has_cover, path FROM books WHERE id = ?"); $sth->execute([$id]); while ($line = $sth->fetch()) { $filename = Config::get(Config::BOOKS_DIR) . "/" . $line["path"] . "/" . "cover.jpg"; if (file_exists($filename)) { return (new Response()) ->withHeader("Content-type", mime_content_type($filename)) ->withHeader('Cache-control', "max-age=" . STATIC_EXPIRES) ->withHeader("Expires", gmdate("D, d M Y H:i:s \G\M\T", time()+STATIC_EXPIRES)) ->withHeader("Last-Modified", gmdate("D, d M Y H:i:s \G\M\T", filemtime($filename))) ->withBody(file_get_contents($filename) ?: ''); } else { return (new Response()) ->withStatus(404) ->withBody(json_encode(["error" => "Not found."])); } } return (new Response()) ->withStatus(404) ->withBody(json_encode(["error" => "Not found."])); } }