-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
74 lines (63 loc) · 2.24 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
<?php
if (isset($_FILES['new_image'])) {
$newImageName = uniqid() . '.jpg';
move_uploaded_file($_FILES['new_image']['tmp_name'], 'img/' . $newImageName);
$message = 'Файл успешно загружен';
}
if ($_GET['delete'] && file_exists($_GET['delete'])) {
unlink($_GET['delete']);
$message = 'Файл успешно удалён';
}
?>
<!DOCTYPE html>
<html lang="en">
<?php include 'includes/head.php' ?>
<body>
<?php include 'includes/header.php'; ?>
<div class="container">
<?php if (isset($message)) : ?>
<div class="alert alert-success">
<?php echo $message?>
</div>
<?php endif; ?>
<div class="row">
<?php $images = glob('img/*.jpg'); ?>
<?php foreach ($images as $i) : ?>
<div class="col-md-4">
<div class="card mb-4 shadow-sm">
<img class="img-thumbnail" src="<?php echo "$i" ?>">
<div class="card-body">
<p class="card-text">Изображение <?php echo $i; ?></p>
<div class="d-flex justify-content-between align-items-center">
<?php if (isset($_COOKIE['auth'])) : ?>
<div class="btn-group">
<a href="/?delete=<?php echo $i; ?>" type="button" class="btn btn-sm btn-outline-secondary">Delete</a>
</div>
<?php endif ?>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php if (isset($_COOKIE['auth'])) : ?>
<form class="col-md-4" method="POST" enctype="multipart/form-data" action="/">
<div class="card mb-4 shadow-sm">
<div class="card-body">
<p class="card-text">
<label for="exampleFile">Загрузка файла</label>
<input type="file" name="new_image" id="exampleFile">
</p>
<div class="d-flex justify-content-between align-items-center">
<div class="btn-group">
<button type="submit" class="btn btn-primary">Загрузить</button>
</div>
</div>
</div>
</div>
</form>
<?php endif ?>
</div>
</div>
<?php include 'includes/footer.php'; ?>
</body>
</html>