Implement routing
[pics.git] / index.php
index a33a56c..0928d93 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,19 +1,19 @@
-<html>
-<a href='upload.php'>Upload</a>
 <?php
 
-require_once __DIR__ . '/db.php';
+// May contain query params
+$request_uri = explode('?', $_SERVER['REQUEST_URI'], 2);
 
-$db = get_db();
-$pics = $db->query('SELECT * from pics');
-while ($pic = $pics->fetchArray()) {
-  $mime_type = $pic['MIME_TYPE'];
-  $file_b64 = $pic['PIC_B64'];
-  $name = $pic['ID'];
-
-  echo "<img src='data:{$mime_type};base64,{$file_b64}' alt='$name'/>";
+switch ($request_uri[0]) {
+    case '/':
+        require './app.php';
+        break;
+    case '/upload':
+        require './upload.php';
+        break;
+    case '/unauthorized':
+        require './unauthorized.php';
+        break;
+    default:
+        header('HTTP/1.0 404 Not Found');
+        die('404 Not Found');
 }
-echo '<p>done with pics</p>';
-?>
-<div>footer</div>
-</html>