forked from lyndonjohn/upload_image
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
76 lines (73 loc) · 2.82 KB
/
index.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
<?php
require_once 'class/Image.php';
$app = new Image;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<button class="default btn-add" onClick="javascript:window.location.href='?upload'">Upload</button><br/>
<table>
<tr>
<th style="width:10px;">ID</th>
<th>IMAGE</th>
<th style="width:150px;"></th>
</tr>
<?php
$stmt = $app->query("SELECT id, image_name FROM images");
$stmt->execute();
while ($row = $stmt->fetch()) {
?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><img width="20%" src="upload/<?php echo $row['image_name']; ?>"></td>
<td>
<button class="default" onClick="javascript:window.location.href='?update&id=<?php echo $row['id']; ?>'">update</button>
<button class="cancel" onClick="javascript:window.location.href='process.php?id=<?php echo $row['id']; ?>'">delete</button>
</td>
</tr>
<?php } ?>
</table>
<hr>
<!-- Upload -->
<?php
if (isset($_GET['upload'])) {
if (isset($_GET['error'])) {
?>
<div class="error"><?php echo $_GET['error']; ?></div>
<?php } ?>
<h4>Upload Form</h4>
<form action="process.php" method="post" enctype="multipart/form-data">
Image: <input required type="file" name="image" id="image" accept="image/*"><br>
<button type="submit" class="default" name="upload">Submit</button>
<button type="button" class="cancel" onClick="javascript:window.location.href='./'">Cancel</button>
</form>
<?php } ?>
<!-- Update -->
<?php
if (isset($_GET['update'])) {
// get image info
$update = $app->query("SELECT image_name FROM images WHERE id=?");
$update->execute([$_GET['id']]);
$rowUpdate = $update->fetch();
if (isset($_GET['error'])) {
?>
<div class="error"><?php echo $_GET['error']; ?></div>
<?php } ?>
<h4>Update Form</h4>
<form action="process.php" method="post" enctype="multipart/form-data">
<img width="50%" src="upload/<?php echo $rowUpdate['image_name']; ?>"><br>
Image: <input required type="file" name="image" id="image" accept="image/*"><br>
<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
<button class="default" type="submit" name="update">Submit</button>
<button type="button" class="cancel" onClick="javascript:window.location.href='./'">Cancel</button>
</form>
<?php } ?>
</body>
</html>