Skip to content

Commit 8d0f45b

Browse files
committed
Initial commit(x3) of Upload2USB stick app: 3 *.php files + UK logo
1 parent 886e98c commit 8d0f45b

File tree

4 files changed

+188
-0
lines changed

4 files changed

+188
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/*
3+
* index.php
4+
* Upload2USB App Index Page
5+
*/
6+
7+
include("upload2usb.php");
8+
9+
//Check if folder for today exists, and get file count if it does
10+
11+
$file_count = getFileCount(getTargetFolderPath(0));
12+
13+
?>
14+
15+
<!DOCTYPE html>
16+
<html>
17+
18+
<head>
19+
<title>IIAB Homework Submission App</title>
20+
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
21+
<meta name="viewport" content="width=device-width, initial-scale=1">
22+
23+
<link rel="stylesheet" href="/common/css/bootstrap4.min.css"/>
24+
<link rel="stylesheet" href="/common/css/fa.all.min.css"/>
25+
<link rel="stylesheet" href="/common/css/font-faces.css"/>
26+
<script src="/common/js/jquery.min.js"></script>
27+
<script src="/common/js/bootstrap4.min.js"></script>
28+
</head>
29+
<body class="text-center" style="background-color:#f5f5f5;">
30+
<div id="container" class="container">
31+
<div class="row">
32+
<div class="col-sm-6 offset-sm-3 text-center" style="padding:15px;">
33+
34+
<form action="submit-hw.php" id="hw_submission_form" method="post" enctype="multipart/form-data">
35+
<img class="mb-4" src="unleash-kids-swing.png" alt="" width="75">
36+
<h1 class="h3 mb-3 font-weight-normal">Internet in a Box Homework Submission</h1>
37+
38+
<label for="submit_hw" style="font-weight:bold;padding-bottom:10px;">Submit your homework here!</label>
39+
<input type="file" name="hw_submission" id="hw_submission"><br/><br/>
40+
<button class="btn btn-dark" name="submit" type="submit" style="width:150px;">Submit</button>
41+
</form>
42+
<br/>
43+
<?php echo $file_count ?> homework files have been submitted today!
44+
45+
</div>
46+
</div>
47+
</div>
48+
49+
</body>
50+
</html>
4.77 KB
Loading
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/*
3+
* upload-file.php
4+
* Upload2USB App - Process Submission
5+
*/
6+
7+
include("upload2usb.php");
8+
9+
//get folder path where homework will be stored
10+
$target_folder_path = getTargetFolderPath(1);
11+
$target_file = $target_folder_path . "/" . basename($_FILES["hw_submission"]["name"]);
12+
$upload_ok = 1;
13+
$upload_msg = "";
14+
15+
if(!isset($_POST["submit"]) || empty(basename($_FILES["hw_submission"]["name"]))) {
16+
$upload_msg = "No file submitted.";
17+
$upload_ok = 0;
18+
} elseif (file_exists($target_file)) {
19+
$upload_msg = "This file already exists.";
20+
$upload_ok = 0;
21+
}
22+
23+
// Check if $upload_ok is set to 0 by an error
24+
if ($upload_ok == 0) {
25+
$upload_msg = "&#x274C; Your file was not uploaded. " . $upload_msg;
26+
27+
// if everything is ok, try to upload file
28+
} else {
29+
if (move_uploaded_file($_FILES["hw_submission"]["tmp_name"], $target_file)) {
30+
$upload_msg = "&#x1F60A; &#x2705; Your homework file ". htmlspecialchars( basename( $_FILES["hw_submission"]["name"])). " was successfully uploaded!";
31+
} else {
32+
$upload_msg = "&#x274C; There was an error uploading your file. " . $upload_msg;
33+
}
34+
}
35+
36+
$file_count = getFileCount($target_folder_path)
37+
38+
?>
39+
40+
<!DOCTYPE html>
41+
<html>
42+
43+
<head>
44+
<title>IIAB Homework Submission App</title>
45+
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
46+
<meta name="viewport" content="width=device-width, initial-scale=1">
47+
48+
<link rel="stylesheet" href="/common/css/bootstrap4.min.css"/>
49+
<link rel="stylesheet" href="/common/css/fa.all.min.css"/>
50+
<link rel="stylesheet" href="/common/css/font-faces.css"/>
51+
<script src="/common/js/jquery.min.js"></script>
52+
<script src="/common/js/bootstrap4.min.js"></script>
53+
</head>
54+
<body class="text-center" style="background-color:#f5f5f5;">
55+
<div id="container" class="container">
56+
<div class="row">
57+
<div class="col-sm-6 offset-sm-3 text-center" style="padding:15px;">
58+
59+
<img class="mb-4" src="unleash-kids-swing.png" alt="" width="75">
60+
<h1 class="h3 mb-3 font-weight-normal">Internet in a Box Homework Submission</h1>
61+
<?php echo $upload_msg ?> <br/>
62+
<?php echo $file_count ?> homework files have been submitted today!
63+
64+
</div>
65+
</div>
66+
</div>
67+
68+
</body>
69+
</html>
70+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/*
3+
* upload2usb.php
4+
* Upload2USB App Helper Functions
5+
*/
6+
7+
8+
//return the first removable USB drive location
9+
function getTargetUSBDriveLocation () {
10+
// Get the first removal USB drive using
11+
// lsblk --output NAME,TRAN,RM,MOUNTPOINT --pairs |grep RM=\"1\" | grep -v MOUNTPOINT=\"\" |grep -oP '[^/]MOUNTPOINT="\K[^"]*' -m 1
12+
// lsblk --output NAME,TRAN,RM,MOUNTPOINT --pairs |grep RM=\"1\" | grep -v MOUNTPOINT=\"\" | cut -d " " -f 4 | cut -d "=" -f 2
13+
14+
$removable_usb_path = trim(str_replace('"', '', shell_exec('lsblk --output NAME,TRAN,RM,MOUNTPOINT --pairs |grep RM=\"1\" | grep -v MOUNTPOINT=\"\" | cut -d " " -f 4 | cut -d "=" -f 2')));
15+
16+
if (empty($removable_usb_path)) {
17+
return "/library/www/html/local_content/";
18+
} else {
19+
20+
return $removable_usb_path . "/";
21+
}
22+
23+
}
24+
25+
//returns folder path where homework will be stored, if create_folder_p = 1, it will create the folder if it doesn't exist
26+
function getTargetFolderPath ($create_folder_p) {
27+
$parent_dir = getTargetUSBDriveLocation();
28+
29+
30+
error_log("PARENTDIR: " . $parent_dir);
31+
32+
$today_folder_name = "UPLOADS." . date("Y-m-d");
33+
$target_folder_path = $parent_dir . $today_folder_name;
34+
35+
if (!file_exists($target_folder_path) && $create_folder_p) {
36+
mkdir($target_folder_path, 0777);
37+
38+
}
39+
40+
return $target_folder_path;
41+
42+
}
43+
44+
//return number of files within a specified folder
45+
function getFileCount ($folder_path) {
46+
return count(glob($folder_path . "/*"));
47+
}
48+
49+
//*** TODO *** check file content to see if it's unique or not
50+
function isFileContentUnique ($file) {
51+
52+
53+
}
54+
55+
56+
//*** TODO **** check if file exists based on file name and return unique name if does
57+
function getUniqueFileName ($filename) {
58+
59+
}
60+
61+
62+
// Check file size - we are not going to check file size for now.
63+
// elseif ($_FILES["hw_submission"]["size"] > 5000000) {
64+
// $upload_msg = "Your file is too large.";
65+
// $upload_ok = 0;
66+
// }
67+
68+
?>

0 commit comments

Comments
 (0)