scelebi commited on
Commit
58e98e4
·
verified ·
1 Parent(s): bbc30ec

Create public/index.php

Browse files
Files changed (1) hide show
  1. public/index.php +76 -0
public/index.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $dbPath = getenv("DB_PATH");
3
+ if (!$dbPath) {
4
+ $dbPath = __DIR__ . "/../db/app.sqlite";
5
+ }
6
+ @mkdir(dirname($dbPath), 0777, true);
7
+
8
+ $pdo = new PDO("sqlite:" . $dbPath);
9
+ $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
10
+
11
+ $pdo->exec("CREATE TABLE IF NOT EXISTS notes (
12
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
13
+ msg TEXT NOT NULL,
14
+ created_at TEXT NOT NULL
15
+ )");
16
+
17
+ $count = (int)$pdo->query("SELECT COUNT(*) FROM notes")->fetchColumn();
18
+ if ($count === 0) {
19
+ $stmt = $pdo->prepare("INSERT INTO notes (msg, created_at) VALUES (?, datetime('now'))");
20
+ $stmt->execute(["Hello from Hugging Face Space"]);
21
+ }
22
+
23
+ $rows = $pdo->query("SELECT id, msg, created_at FROM notes ORDER BY id DESC LIMIT 10")
24
+ ->fetchAll(PDO::FETCH_ASSOC);
25
+ ?>
26
+ <!doctype html>
27
+ <html lang="en">
28
+ <head>
29
+ <meta charset="utf-8" />
30
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
31
+ <title>PHP + SQLite on Hugging Face</title>
32
+ <style>
33
+ body{font-family:system-ui,Arial;margin:24px;max-width:900px}
34
+ code{background:#f3f3f3;padding:2px 6px;border-radius:6px}
35
+ table{border-collapse:collapse;width:100%;margin-top:12px}
36
+ th,td{border:1px solid #ddd;padding:8px;text-align:left}
37
+ </style>
38
+ </head>
39
+ <body>
40
+ <h1>PHP + SQLite (Hugging Face Docker Space)</h1>
41
+ <p>DB Path: <code><?= htmlspecialchars($dbPath) ?></code></p>
42
+
43
+ <form method="post">
44
+ <input name="msg" placeholder="Yeni not..." style="padding:8px;width:70%" />
45
+ <button style="padding:8px 12px">Ekle</button>
46
+ </form>
47
+
48
+ <?php
49
+ if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["msg"])) {
50
+ $m = trim($_POST["msg"]);
51
+ if ($m !== "") {
52
+ $stmt = $pdo->prepare("INSERT INTO notes (msg, created_at) VALUES (?, datetime('now'))");
53
+ $stmt->execute([$m]);
54
+ header("Location: " . $_SERVER["REQUEST_URI"]);
55
+ exit;
56
+ }
57
+ }
58
+ ?>
59
+
60
+ <h2>Son 10 kayıt</h2>
61
+ <table>
62
+ <thead><tr><th>ID</th><th>Mesaj</th><th>Tarih</th></tr></thead>
63
+ <tbody>
64
+ <?php foreach ($rows as $r): ?>
65
+ <tr>
66
+ <td><?= (int)$r["id"] ?></td>
67
+ <td><?= htmlspecialchars($r["msg"]) ?></td>
68
+ <td><?= htmlspecialchars($r["created_at"]) ?></td>
69
+ </tr>
70
+ <?php endforeach; ?>
71
+ </tbody>
72
+ </table>
73
+
74
+ <p><small>Not: Free tier’da disk ephemeraldir; restart/stop sonrasi DB sıfırlanabilir.</small></p>
75
+ </body>
76
+ </html>