-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddrobot.php
135 lines (119 loc) · 4.53 KB
/
addrobot.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
include 'password.php';
if(isset($_POST['submit'])) {
$err = FALSE;
$message = '';
$target_path = '';
$servername = 'localhost';
$username = 'www';
$dbname = 'robotics';
$conn = new mysqli($servername, $username, $password, $dbname);
$name = mysqli_real_escape_string($conn, $_POST['name']);
$number = mysqli_real_escape_string($conn, $_POST['number']);
$leaders = mysqli_real_escape_string($conn, $_POST['leaders']);
$strengths = mysqli_real_escape_string($conn, $_POST['strengths']);
$weaknesses = mysqli_real_escape_string($conn, $_POST['weaknesses']);
$notes = mysqli_real_escape_string($conn, $_POST['notes']);
if (!$name) {
$err = TRUE;
}
if (!$number) {
$err = TRUE;
}
if ($conn->connect_error) {
die('Connection failed: ' . $conn->connect_error);
$err = TRUE;
}
try {
if (isset($_FILES['file'])) {
if (!isset($_FILES['file']['error']) ||
is_array($_FILES['file']['error'])
) {
throw new RuntimeException('An error has occured.');
}
switch ($_FILES['file']['error']) {
case UPLOAD_ERR_OK:
break;
case UPLOAD_ERR_NO_FILE:
throw new RuntimeException('No file sent.');
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
throw new RuntimeException('Exceeded filesize limit.');
default:
throw new RuntimeException('An error has occured.');
}
# if ($_FILES['file']['size'] > 10000000) {
# throw new RuntimeException('Exceeded filesize limit.');
# }
$file_name = time().'_'.basename($_FILES['file']['name']);
$target_path = 'img/upload/'.$file_name;
$finfo = new finfo(FILEINFO_MIME_TYPE);
if (false === $ext = array_search(
strtolower($finfo->file($_FILES['file']['tmp_name'])),
array(
'.png' => 'image/png',
'.PNG' => 'image/PNG',
'.jpg' => 'image/jpeg',
'.jpeg' => 'image/jpeg',
'.JPG' => 'image/jpeg',
'.JPEG' => 'image/jpeg',
),
true
)) {
throw new RuntimeException('Only .png and jpeg files can be uploaded');
}
if (move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
exec("convert -define jpeg:size=200x200 $target_path -thumbnail 390x290^ -gravity center -extent 390x290 $target_path");
$message = basename($_FILES['file']['name'])." has been uploaded.";
} else {
throw new RuntimeException('Failed to move file');
}
}
} catch (RuntimeException $e) {
$err = TRUE;
$message = $e->getMessage();
echo $message;
}
$sql = "INSERT INTO pit_scout (name, number, leaders, strengths, weaknesses, notes, image) VALUES ('$name', '$number', '$leaders', '$strengths', '$weaknesses', '$notes', '$target_path')";
if ($err || $conn->query($sql) === FALSE) {
echo 'Error' . $sql . $conn->error;
}
$conn->close();
}
?>
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="css/form.css">
</head>
</body>
<div class="container">
<form id="contact" action="" method="post" enctype="multipart/form-data">
<h3>Robot Addition Form</h3>
<fieldset>
<input placeholder="Team Name" name="name" type="text" tabindex="1" required autofocus>
</fieldset>
<fieldset>
<input placeholder="Team Number" name="number" type="number" min="0" tabindex="2" required>
</fieldset>
<fieldset>
<textarea placeholder="List Leaders" name="leaders" tabindex="3"></textarea>
</fieldset>
<fieldset>
<textarea placeholder="Robot Strengths" name="strengths" tabindex="4"></textarea>
</fieldset>
<fieldset>
<textarea placeholder="Robot Weaknesses" name="weaknesses" tabindex="5"></textarea>
</fieldset>
<fieldset>
<textarea placeholder="Other Notes" name="notes" tabindex="6"></textarea>
</fieldset>
<fieldset>
<p><b>Robot Image (png/jpg)</b></p>
<input name="file" type="file" tabindex="7" accept="image/*" required>
</fieldset>
<fieldset>
<button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Submit</button>
</fieldset>
</form>
</div>
</body>