-
Notifications
You must be signed in to change notification settings - Fork 2
/
upload.php
86 lines (77 loc) · 2.71 KB
/
upload.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
<?PHP
if (!file_exists('users.json')) {
touch('users.json');
}
if (!file_exists('uuid.json')) {
touch('uuid.json');
}
if (!file_exists('./logs/log_'.date("j.n.Y").'.log')) {
touch('./logs/log_'.date("j.n.Y").'.log');
file_put_contents('./logs/log_'.date("j.n.Y").'.log', "".PHP_EOL, FILE_APPEND);
}
if(!empty($_FILES['uploaded_file']))
{
$path = "capes/";
$path = $path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
header("Location: index.php");
$log = "[".date("F j, Y, g:i a")."] Image File Uploaded: | Name: ".$_FILES['uploaded_file']['name'].PHP_EOL;
file_put_contents('./logs/log_'.date("j.n.Y").'.log', $log, FILE_APPEND);
} else{
echo "There was an error uploading the file, please try again!";
$log = "[".date("F j, Y, g:i a")."] Image File Error: There was an error uploading the file".PHP_EOL;
file_put_contents('./logs/log_'.date("j.n.Y").'.log', $log, FILE_APPEND);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cape API</title>
<link rel="shortcut icon" href="assets/NABIA.png" />
<link rel="stylesheet" type="text/css" href="assets/style.css">
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<header><h1>Nabia | Capes API</h1>
<a class="add" href="index.php">Home</a>
</header>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<p>Upload Cape Image</p>
<input type="file" id="file" name="uploaded_file" accept="image/x-png,image/jpg,image/jpeg"></input><br/>
<button type="submit" name="Upload" >Upload</button>
</form>
<script type="text/javascript">
var uploadField = document.getElementById("file");
uploadField.onchange = function() {
if(this.files[0].size > 200000){
alert("File has exeded the maximum size of: 200kb");
this.value = "";
};
};
</script>
<script type="text/javascript">
var fileInput = document.getElementById("file");
fileInput .onchange = function(e) {
e.preventDefault();
var file = fileInput.files && fileInput.files[0];
var img = new Image();
img.src = window.URL.createObjectURL(file);
img.onload = function() {
var width = img.naturalWidth,
height = img.naturalHeight;
window.URL.revokeObjectURL(img.src);
if (width <= 64 && height <= 32) {
} else if (width <= 128 && height <= 64) {
} else if (width <= 2048 && height <= 1024) {
} else {
fileInput.value = ""
alert("Your image doesnt match the accepted dimentions of: 2048/1024, 128/64, 64/32")
}
};
};
</script>
</body>
</html>