-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.php
More file actions
118 lines (93 loc) · 3.05 KB
/
Copy pathupdate.php
File metadata and controls
118 lines (93 loc) · 3.05 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<?php
session_start();
if(!isset($_SESSION['id'])) {
header("Location: login.php" );
}
?>
<style>
body {
text-align: center;
}
.form-group {
display: flex;
justify-content: space-between;
width: 25%;
margin: auto;
padding-bottom: 18px;
}
label,
input {
font-size: 18px;
}
.back{
margin-bottom: 25px;
}
.back a{
font-size: 18px;
}
</style>
</head>
<body>
<?php
include "common.php";
if(isset($_POST['submit'])){
$id = $_POST['id'];
$name = $_POST['name'];
$file_loc = $_FILES['picture']['tmp_name'];
$ext = pathinfo($_FILES['picture']['name'], PATHINFO_EXTENSION);
if (is_uploaded_file($file_loc)){
$old_picture_name = $_POST['old-name'];
move_uploaded_file($file_loc, 'images/'.$name.'.'.$ext);
$con->query("UPDATE devices SET name='$name', picture_file_name='$name.$ext' WHERE id='$id'");
unlink($old_picture_name);
}else {
$con->query("UPDATE devices SET name='$name' WHERE id='$id'");
}
header("Location: devices.php");
}else if(isset($_GET['id'])){
$id = $_GET['id'];
$result = $con->query("SELECT name, picture_file_name FROM devices WHERE id='$id'");
if($result->num_rows == 1){
$data = $result->fetch_assoc();
$name = $data['name'];
$picture_file_name = $data['picture_file_name'];
}
}
?>
<h1>Update Device</h1>
<div class="back">
<a href="devices.php">Back to Devices Dashboard</a>
</div>
<form action="update.php" method="POST" enctype="multipart/form-data">
<input type="hidden" name="id" value='<?=$id?>'>
<input type="hidden" name="old-name" value='<?php echo $picture_file_name?>'>
<div class="form-group">
<label for="name">Name of Device: </label>
<input type="text" name="name" id="name" value='<?php echo $name?>'/>
</div>
<div>
<?php
if (isset($picture_file_name)){
?>
<h3>Old Image</h3>
<img src='images/<?php echo $picture_file_name ?>' alt="image here" height=250/>
<h4>Enter new image if you want to update file</h4>
<?php }else { ?>
<h4>Enter image</h4>
<?php } ?>
</div>
<div class="form-group">
<label for="picture">Picture: </label>
<input type="file" name="picture" id="picture" />
</div>
<input type="submit" value="Update Device" name="submit" />
</form>
</body>
</html>