55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
|
|
require 'header.php';
|
|
require 'variables.php';
|
|
require 'functions.php';
|
|
|
|
require_login();
|
|
|
|
$now = time();
|
|
$time = date("YmdHis", $now);
|
|
|
|
$username = $_SESSION['username'];
|
|
|
|
$fileondrive = false;
|
|
$goodtodown = false;
|
|
|
|
if ( isset($_REQUEST['id']) ) {
|
|
$query = "SELECT id, path, filename FROM books WHERE id=:id";
|
|
$sth = $globaldbh->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<br>\n");
|
|
echo("trying to do something you shouldn't.<br><br>\n");
|
|
echo("Please try again later.\n");
|
|
}
|
|
|
|
// vim: sw=3 ts=3 et:
|