-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodifygallery.php
More file actions
93 lines (78 loc) · 2.98 KB
/
Copy pathmodifygallery.php
File metadata and controls
93 lines (78 loc) · 2.98 KB
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
<?php
session_start();
if(!isset($_SESSION['email']) || empty($_SESSION['email'])){
http_response_code(401);
echo("Unauthorized");
exit(0);
}
$database_key = file_get_contents('/api-keys/database.key');
$mysqli_con = new mysqli("localhost","http",$database_key,"cleanlineslawncare");
$valid_database = true;
foreach($_POST as $key => $value) {
if (strpos($key, 'order_') === 0) {
$gallery_picture_id = str_replace("order_","",$key);
if(!is_numeric($gallery_picture_id) || !is_numeric($value)){
continue;
}
$gallery_picture_id = strval($gallery_picture_id);
$gallery_picture_order = strval($value);
if(!mysqli_connect_errno()){
$sql = "UPDATE gallery_pictures SET gallery_picture_order=? where gallery_picture_id=?;";
if($stmt = $mysqli_con->prepare($sql)){
$stmt->bind_param('ii', $gallery_picture_order, $gallery_picture_id);
$stmt->execute();
$stmt->store_result();
$stmt->close();
} else {
$valid_database = false;
}
} else {
$valid_database = false;
}
}
}
foreach($_POST as $key => $value) {
if (strpos($key, 'delete_') === 0) {
if($value != "1"){
continue;
}
$gallery_picture_id = str_replace("delete_","",$key);
if(!is_numeric($gallery_picture_id)){
continue;
}
$gallery_picture_id = strval($gallery_picture_id);
if(!mysqli_connect_errno()){
$sql = "SELECT gallery_picture_location FROM gallery_pictures WHERE gallery_picture_id=?;";
if($stmt = $mysqli_con->prepare($sql)){
$stmt->bind_param('i', $gallery_picture_id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($gallery_picture_location);
while( $stmt->fetch()){
unlink(__DIR__ . "/gallery/" . $gallery_picture_location);
}
}
$sql = "DELETE FROM gallery_pictures WHERE gallery_picture_id=?;";
if($stmt = $mysqli_con->prepare($sql)){
$stmt->bind_param('i', $gallery_picture_id);
$stmt->execute();
$stmt->store_result();
$stmt->close();
} else {
$valid_database = false;
}
} else {
$valid_database = false;
}
}
}
$mysqli_con->close();
if( !$valid_database ){
http_response_code(500);
echo("Invalid database");
exit(0);
}
http_response_code(200);
echo("Success!");
exit(0);
?>