-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprocess.php
75 lines (64 loc) · 2.19 KB
/
process.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
<?php
require_once 'class/Image.php';
$app = new Image;
if (isset($_POST['upload'])) {
$image = $_FILES['image']['name'];
$image_tmp = $_FILES['image']['tmp_name'];
$image_size = $_FILES['image']['size'];
$image_ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
// check if file is empty
if (empty($image)) {
header("Location: ./?upload&error=Select image to upload.");
die;
}
// valid image extension
$valid_ext = ['jpeg', 'jpg', 'JPEG', 'JPG', 'png', 'PNG'];
// check if image has valid extension
if (in_array($image_ext, $valid_ext)) {
// check image size
if ($image_size > 100000) {
header("Location: ./?upload&error=Image must not be more than 100kb.");
die;
}
// if there is no error, go to upload method in Image.php class
if ($app->upload($image, $image_tmp, $image_ext)) {
header("Location: ./");
}
} else {
header("Location: ./?upload&error=Image doesn't have a valid extension.");
}
}
if (isset($_POST['update'])) {
$image = $_FILES['image']['name'];
$image_tmp = $_FILES['image']['tmp_name'];
$image_size = $_FILES['image']['size'];
$image_ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
$id = $_POST['id'];
if (empty($image)) {
header("Location: ./?upload&error=Select image to upload.");
die;
}
// valid image extension
$valid_ext = ['jpeg', 'jpg', 'JPEG', 'JPG', 'png', 'PNG'];
// check if image has valid extension
if (in_array($image_ext, $valid_ext)) {
// check image size
if ($image_size > 100000) {
header("Location: ./?upload&error=Image must not be more than 100kb.");
die;
}
// if there is no error, go to update method in Image.php class
if ($app->update($image, $image_tmp, $image_ext, $id)) {
header("Location: ./");
}
} else {
header("Location: ./?upload&error=Image doesn't have a valid extension.");
}
}
if (isset($_GET['id'])) {
$id = $_GET['id'];
// go to delete method
if ($app->delete($id)) {
header("Location: ./");
}
}