-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
73 lines (58 loc) · 1.83 KB
/
upload.php
File metadata and controls
73 lines (58 loc) · 1.83 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
<?php
$currentDir = getcwd();
//$uploadDirectory = "/uploads/";
$errors = []; // Store all foreseen and unforseen errors here
$fileExtensions = ['.json','json']; // Get all the file extensions
$fileName = $_FILES['myfile']['name'];
$fileSize = $_FILES['myfile']['size'];
$fileTmpName = $_FILES['myfile']['tmp_name'];
$fileType = $_FILES['myfile']['type'];
$fileExtension = strtolower(end(explode('.',$fileName)));
$uploadPath = $currentDir . basename($fileName);
if (isset($_POST['submit'])) {
if (! in_array($fileExtension,$fileExtensions)) {
$errors[] = "This file extension is not allowed. Please upload a JSON file. ";
}
if ($fileSize > 5000000) {
$errors[] = "This file is more than 5MB. Sorry, it has to be less than or equal to 2MB";
}
if (empty($errors)) {
$didUpload = move_uploaded_file($fileTmpName, $uploadPath);
if ($didUpload) {
echo "The file " . basename($fileName) . " has been uploaded";
} else {
echo "An error occurred somewhere. Try again or contact the admin";
}
} else {
foreach ($errors as $error) {
echo $error . "These are the errors" . "\n";
}
}
}
?>
<!DOCTYPE html>
<html lang= "en">
<head>
<meta charset="UTF-8">
<title>Admin Page</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
#header{
height: 5%;
width: 70%;
}
#title-text{
text-align: center;
color: #FFDF00;
}
html, body {
background: #172697;
height: 100%;
margin: 0;
text-align: center;
color:#FFDF00;
padding: 0;
</style>
</head>