-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpictures.php
More file actions
83 lines (68 loc) · 2.15 KB
/
pictures.php
File metadata and controls
83 lines (68 loc) · 2.15 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
$image = new Images(null, null, null);
$image->createImageTable($connection);
// Handle image upload
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
$uploadedFile = $_FILES['file'];
$imageName = $uploadedFile['name'];
$imageData = file_get_contents($uploadedFile['tmp_name']);
$imageID = Get_new_id_pics($connection, "images", "id");
$_SESSION['uploaded_image_id'] = $imageID;
$image->uploadImage($imageID, $imageData, $imageName, $connection);
}
// Handle image search
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['search'])) {
$searchId = $_POST['searchId'];
$searchResult = $image->getImageById($searchId, $connection);
if ($searchResult) {
$imageName = $searchResult['image_name'];
$imageData = base64_encode($searchResult['image_data']);
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Upload and Gallery</title>
<style>
#drop-area {
border: 2px dashed #ccc;
border-radius: 8px;
padding: 20px;
text-align: center;
cursor: pointer;
}
.image-container {
margin: 10px;
}
img {
max-width: 200px;
max-height: 200px;
}
</style>
</head>
<body>
<form enctype="multipart/form-data" action="" method="POST">
<label for="fileInput">Choose Image:</label>
<input type="file" id="fileInput" name="file" accept="image/*" required>
<button type="submit" name="upload">Upload</button>
</form>
<!--
<form action="" method="POST">
<label for="searchId">Search Image by ID:</label>
<input type="text" id="searchId" name="searchId" required>
<button type="submit" name="search">Search</button>
</form>
-->
<?php
if (isset($searchResult)) {
echo '<div class="image-container">';
echo '<img src="data:image/jpeg;base64,' . $imageData . '" alt="Image">';
echo '<p>ID: ' . $searchId . '</p>';
echo '</div>';
}
?>
</body>
</html>