-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.php
More file actions
49 lines (43 loc) · 1.29 KB
/
image.php
File metadata and controls
49 lines (43 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
$id = $_GET['id'] ?? '';
if (!is_string($id) || $id === '') {
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
if (is_string($requestUri)) {
$path = parse_url($requestUri, PHP_URL_PATH);
if (is_string($path) && preg_match('#^/image/([a-f0-9]{32})$#', $path, $matches) === 1) {
$id = $matches[1];
}
}
}
if (!is_string($id) || !preg_match('/^[a-f0-9]{32}$/', $id)) {
http_response_code(404);
echo 'Image not found';
exit;
}
$uploadsDir = __DIR__ . DIRECTORY_SEPARATOR . 'uploads';
$matches = glob($uploadsDir . DIRECTORY_SEPARATOR . $id . '.*') ?: [];
if (count($matches) === 0) {
http_response_code(404);
echo 'Image not found';
exit;
}
$filename = basename($matches[0]);
$imageUrl = '/uploads/' . rawurlencode($filename);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Shared Image</title>
<link rel="stylesheet" href="/public/styles.css" />
</head>
<body>
<main class="viewer-container">
<h1>Shared Image</h1>
<img src="<?= htmlspecialchars($imageUrl, ENT_QUOTES, 'UTF-8'); ?>" alt="Shared image" class="viewer-image" />
<p><a href="/">Upload another image</a></p>
</main>
</body>
</html>