summaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
Diffstat (limited to 'static')
-rw-r--r--static/php/show.php55
1 files changed, 25 insertions, 30 deletions
diff --git a/static/php/show.php b/static/php/show.php
index 4705914..6dcf06a 100644
--- a/static/php/show.php
+++ b/static/php/show.php
@@ -1,6 +1,4 @@
<?php
-session_start();
-
/**
* Finds file in a database and shows its content.
*
@@ -42,38 +40,35 @@ function httpDate($timestamp)
return gmdate('D, d M Y H:i:s T', $timestamp);
}
-try {
- // Get file from a database
- $q = $db->prepare('SELECT filename, mime, size, date FROM files
- WHERE filename = (:filename)');
- $q->bindValue(':filename', $_GET['filename'], PDO::PARAM_STR);
+$q = $db->prepare('SELECT filename, mime, size, date FROM files
+ WHERE filename = (:filename)');
+$q->bindValue(':filename', $_GET['filename'], PDO::PARAM_STR);
- if ($q->execute()) {
- if ($q->rowCount() > 0) {
- $file = $q->fetch(PDO::FETCH_OBJ);
+if ($q->execute()) {
+ if ($q->rowCount() > 0) {
+ $file = $q->fetch(PDO::FETCH_OBJ);
- // File metadata
- header('Content-Length: ' . $file->size);
- header('Content-Type: ' . $file->mime);
+ // File metadata
+ header('Content-Length: ' . $file->size);
+ header('Content-Type: ' . $file->mime);
- // Cache control
- header('Cache-Control: public, immutable, max-age=' . ONE_YEAR);
- header('Expires: ' . httpDate(time() + ONE_YEAR));
- header('Last-Modified: ' . httpDate(strtotime($file->date)));
- header('Pragma: public');
+ // Cache control
+ header('Cache-Control: public, immutable, max-age=' . ONE_YEAR);
+ header('Expires: ' . httpDate(time() + ONE_YEAR));
+ header('Last-Modified: ' . httpDate(strtotime($file->date)));
+ header('Pragma: public');
- readfile(POMF_FILES_ROOT . $file->filename);
- exit;
- } else {
- throw new Exception('File not found', 404);
- }
+ readfile(POMF_FILES_ROOT . $file->filename);
+ exit;
} else {
- $err = $q->errorInfo();
- throw new Exception('SQL error: ' . $err[2], 500);
- }
-} catch (Exception $e) {
- header('Content-Type: text/plain', true, $e->getCode());
+ // If file not found, show 404 page
+ header('Cache-Control: no-cache, no-store, must-revalidate');
+ header('Pragma: no-cache');
+ http_response_code(404);
- echo $e->getCode() . ': ' . $e->getMessage();
- exit;
+ include '404.html';
+ }
+} else {
+ header('Content-Type: text/plain', true, 500);
+ echo $q->errorInfo()[2];
}