-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
116 lines (85 loc) · 2.53 KB
/
search.php
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
session_start();
if (!$_SESSION["verified"]) {
header("Location: /login.php?continue=" . $_SERVER["SCRIPT_NAME"]);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Search</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="/assets/main.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div id="searchContainer">
<div id="body">
<!-- Body start -->
<ul class="nav">
<li class="navli"><a href="/">Home</a></li>
<li class="navli"><a class="active" href="/search.php">Search</a></li>
</ul>
<?php
$searchTag = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$searchTag = clean_input($_POST["search"]);
}
?>
<form class="searchForm" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" enctype="multipart/form-data">
<button class="submitBtn" type="submit"><i class="fa fa-search"></i></button>
<span class="searchSpan"><input class="searchField" type="text" placeholder="Search..." name="search" value=<?php echo $searchTag; ?>></span>
</form>
<?php
$servername = "localhost";
$username = "root";
include 'assets/hidden.php';
$password = $mySQLPassword;
$database = "images";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "<div class='grid'>";
$res = mysqli_query($conn, "SELECT * FROM photos WHERE FIND_IN_SET('" . $searchTag . "', tags)");
while($row = mysqli_fetch_assoc($res)) {
$imageLink = "/images/" . $row['id'] . "." . $row['fileType'];
$viewLink = "/viewphoto.php?id=" . $row['id'];
echo "<div>";
echo "<a href=" . $imageLink . ">";
echo "<div style='
background: url(images/thumb" . $row['id']. "." . $row['fileType'] . ") 50% 50% no-repeat;
background-size: cover;
height: 100%;
width: 100%;
'>";
echo "</div>";
echo "</a>";
echo "</div>";
}
echo "</div>";
}
function clean_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<!-- Body end -->
</div>
<div id="footer">
<!-- Footer start -->
<center>
<br>
<p class="fieldExplanation"><?php echo (100 - intval(file_get_contents("percent.txt"))); ?>% storage remaining</p>
</center>
<!-- Footer end -->
</div>
</div>
</body>
</html>