-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaintain2.php
169 lines (153 loc) · 4.93 KB
/
maintain2.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
// Koneksi ke database
include 'koneksi.php';
if (isset($_POST['compress_images'])) {
// Query untuk mengambil semua data gambar yang akan dikompres
$query = "SELECT nama, waktu, img_dir FROM laporan";
$result = mysqli_query($conn, $query);
while ($row = mysqli_fetch_assoc($result)) {
$imgData = $row['img_dir'];
// Membuat image dari string binari
$image = imagecreatefromstring($imgData);
if ($image !== false) {
// Output buffering untuk mendapatkan data gambar yang dikompresi
ob_start();
imagejpeg($image, null, 25); // 75 adalah kualitas kompresi
$compressedImage = ob_get_contents();
ob_end_clean();
// Update gambar yang sudah dikompresi ke database
$updateQuery = "UPDATE laporan SET img_dir = ? WHERE nama = ? AND waktu = ?";
$stmt = mysqli_prepare($conn, $updateQuery);
mysqli_stmt_bind_param($stmt, 'sss', $compressedImage, $row['nama'], $row['waktu']);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
// Menghancurkan image dari memory untuk menghemat resource
imagedestroy($image);
}
}
echo "<script>alert('Semua gambar berhasil dikompresi!');</script>";
}
// Mendapatkan nomor halaman dari query string, jika tidak ada, set ke halaman 1
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$limit = 50; // Jumlah data per halaman
$offset = ($page - 1) * $limit;
// Query untuk mengambil data dengan batasan limit dan offset
$query = "SELECT nama, waktu, img_dir FROM laporan LIMIT $limit OFFSET $offset";
$result = mysqli_query($conn, $query);
// Menampilkan data
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Data Laporan dengan Kompresi</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
color: #333;
}
.container {
width: 90%;
margin: auto;
overflow: hidden;
}
table {
width: 100%;
margin: 20px 0;
border-collapse: collapse;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 10px;
text-align: left;
}
th {
background-color: #333;
color: #fff;
}
.pagination {
margin: 20px 0;
text-align: center;
}
.pagination a {
color: #333;
padding: 8px 16px;
text-decoration: none;
border: 1px solid #ddd;
margin: 0 4px;
}
.pagination a.active {
background-color: #333;
color: #fff;
border: 1px solid #333;
}
.compress-btn {
margin: 20px 0;
text-align: center;
}
.compress-btn button {
padding: 10px 20px;
font-size: 16px;
color: #fff;
background-color: #333;
border: none;
cursor: pointer;
}
.compress-btn button:hover {
background-color: #555;
}
</style>
</head>
<body>
<div class="container">
<h1>Data Laporan dengan Kompresi</h1>
<!-- Form untuk mengompres semua gambar -->
<div class="compress-btn">
<form method="post">
<button type="submit" name="compress_images">Kompres Semua Gambar</button>
</form>
</div>
<table>
<thead>
<tr>
<th>Nama</th>
<th>Waktu</th>
<th>Image</th>
</tr>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<td><?php echo htmlspecialchars($row['nama']); ?></td>
<td><?php echo htmlspecialchars($row['waktu']); ?></td>
<td>
<?php
// Menampilkan gambar
$imgData = $row['img_dir'];
echo '<img src="data:image/jpeg;base64,' . base64_encode($imgData) . '" width="100" />';
?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="pagination">
<?php
// Menentukan jumlah halaman
$totalQuery = "SELECT COUNT(*) AS total FROM laporan";
$totalResult = mysqli_query($conn, $totalQuery);
$totalData = mysqli_fetch_assoc($totalResult)['total'];
$totalPages = ceil($totalData / $limit);
// Menampilkan link halaman
for ($i = 1; $i <= $totalPages; $i++) {
echo '<a href="?page=' . $i . '" class="' . ($i == $page ? 'active' : '') . '">' . $i . '</a>';
}
?>
</div>
</div>
</body>
</html>