prepare($query);
$sth->bindValue(":id", (int) $_REQUEST['id'], PDO::PARAM_INT);
$sth->execute();
if ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) {
$filename = $row['filename'];
$relativefile = $row['path'] . "/" . $filename;
$curfile = BOOKDIR . $relativefile;
if ( is_file($curfile) ) {
$goodtodown = true;
$filesize = filesize($curfile);
}
}
}
if ($goodtodown) {
$log = fopen("/var/www/booklogs","a");
fputs($log, "{$username},{$time},{$curfile},{$filesize}\n");
fclose($log);
header("Pragma: public");
if ( substr($filename, -4) == "epub" ) {
header("Content-Type: application/epub+zip");
} else {
header("Content-Type: application/octet-stream");
}
header("Content-Disposition: attachment; filename=\"" . trim($filename) . "\"");
header("Content-Description: " . trim($filename));
header("Content-Length: $filesize");
readfile("$curfile");
exit();
} else {
echo("Either something is broken or you are
\n");
echo("trying to do something you shouldn't.
\n");
echo("Please try again later.\n");
}
// vim: sw=3 ts=3 et: