-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.php
More file actions
32 lines (27 loc) · 747 Bytes
/
image.php
File metadata and controls
32 lines (27 loc) · 747 Bytes
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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "library_db";
$port = 3307;
$conn = new mysqli($servername, $username, $password, $dbname, $port);
if ($conn->connect_error) {
http_response_code(500);
exit("Database connection failed");
}
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id <= 0) {
http_response_code(400);
exit("Invalid ID");
}
$sql = "SELECT book_cover FROM library WHERE id=$id";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
if ($row && $row['book_cover']) {
header("Content-Type: image/jpeg"); // 你也可以动态判断 MIME 类型
echo $row['book_cover'];
} else {
http_response_code(404);
exit("Image not found");
}
$conn->close();