-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupload_input.php
More file actions
59 lines (40 loc) · 1.54 KB
/
Copy pathupload_input.php
File metadata and controls
59 lines (40 loc) · 1.54 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
<?php
//CORS Headers
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
$problem = $_POST['problem'];
$team = $_POST['team'];
//connecting to SQL Database
$con = mysqli_connect("localhost", "root", "", "othscmsdb");
$filename = $_FILES['file']['name'];
//Stores the filetype e.g image/jpeg
$filetype = $_FILES['file']['type'];
//Stores any error codes from the upload.
$fileerror = $_FILES['file']['error'];
//Stores the tempname as it is given by the host when uploaded.
$filetemp = $_FILES['file']['tmp_name'];
//The path you wish to upload the file to
$filePath = "submissions/" . $team . "/";
//separating by problem
if (!is_dir($filePath.$problem))
mkdir($filePath.$problem, 0700);
$filePath = $filePath . $problem . "/";
if(is_uploaded_file($filetemp)) {
//date for separating attempts
$date = date('Y-m-d-H-i-s');
mkdir($filePath.$date, 0700);
$filePath = $filePath . $date . "/";
if(move_uploaded_file($filetemp, $filePath . $filename)) {
$filePath = $filePath . $filename;
$sql = "INSERT INTO submissions (user, problemName, filePath) VALUES (\"$team\", \"$problem\", \"$filePath\")";
$res = mysqli_query($con, $sql);
echo "Sussecfully uploaded your image.";
}
else {
echo "Failed to move your image.";
}
}
else {
echo "Failed to upload your image.";
}
?>