1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-03-09 15:40:17 +00:00

Initial commit(x3) of Upload2USB stick app: 3 *.php files + UK logo

This commit is contained in:
root 2025-01-05 16:35:38 -05:00
parent 886e98c0cb
commit 8d0f45bd4d
4 changed files with 188 additions and 0 deletions

View file

@ -0,0 +1,50 @@
<?php
/*
* index.php
* Upload2USB App Index Page
*/
include("upload2usb.php");
//Check if folder for today exists, and get file count if it does
$file_count = getFileCount(getTargetFolderPath(0));
?>
<!DOCTYPE html>
<html>
<head>
<title>IIAB Homework Submission App</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/common/css/bootstrap4.min.css"/>
<link rel="stylesheet" href="/common/css/fa.all.min.css"/>
<link rel="stylesheet" href="/common/css/font-faces.css"/>
<script src="/common/js/jquery.min.js"></script>
<script src="/common/js/bootstrap4.min.js"></script>
</head>
<body class="text-center" style="background-color:#f5f5f5;">
<div id="container" class="container">
<div class="row">
<div class="col-sm-6 offset-sm-3 text-center" style="padding:15px;">
<form action="submit-hw.php" id="hw_submission_form" method="post" enctype="multipart/form-data">
<img class="mb-4" src="unleash-kids-swing.png" alt="" width="75">
<h1 class="h3 mb-3 font-weight-normal">Internet in a Box Homework Submission</h1>
<label for="submit_hw" style="font-weight:bold;padding-bottom:10px;">Submit your homework here!</label>
<input type="file" name="hw_submission" id="hw_submission"><br/><br/>
<button class="btn btn-dark" name="submit" type="submit" style="width:150px;">Submit</button>
</form>
<br/>
<?php echo $file_count ?> homework files have been submitted today!
</div>
</div>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

View file

@ -0,0 +1,70 @@
<?php
/*
* upload-file.php
* Upload2USB App - Process Submission
*/
include("upload2usb.php");
//get folder path where homework will be stored
$target_folder_path = getTargetFolderPath(1);
$target_file = $target_folder_path . "/" . basename($_FILES["hw_submission"]["name"]);
$upload_ok = 1;
$upload_msg = "";
if(!isset($_POST["submit"]) || empty(basename($_FILES["hw_submission"]["name"]))) {
$upload_msg = "No file submitted.";
$upload_ok = 0;
} elseif (file_exists($target_file)) {
$upload_msg = "This file already exists.";
$upload_ok = 0;
}
// Check if $upload_ok is set to 0 by an error
if ($upload_ok == 0) {
$upload_msg = "&#x274C; Your file was not uploaded. " . $upload_msg;
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["hw_submission"]["tmp_name"], $target_file)) {
$upload_msg = "&#x1F60A; &#x2705; Your homework file ". htmlspecialchars( basename( $_FILES["hw_submission"]["name"])). " was successfully uploaded!";
} else {
$upload_msg = "&#x274C; There was an error uploading your file. " . $upload_msg;
}
}
$file_count = getFileCount($target_folder_path)
?>
<!DOCTYPE html>
<html>
<head>
<title>IIAB Homework Submission App</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/common/css/bootstrap4.min.css"/>
<link rel="stylesheet" href="/common/css/fa.all.min.css"/>
<link rel="stylesheet" href="/common/css/font-faces.css"/>
<script src="/common/js/jquery.min.js"></script>
<script src="/common/js/bootstrap4.min.js"></script>
</head>
<body class="text-center" style="background-color:#f5f5f5;">
<div id="container" class="container">
<div class="row">
<div class="col-sm-6 offset-sm-3 text-center" style="padding:15px;">
<img class="mb-4" src="unleash-kids-swing.png" alt="" width="75">
<h1 class="h3 mb-3 font-weight-normal">Internet in a Box Homework Submission</h1>
<?php echo $upload_msg ?> <br/>
<?php echo $file_count ?> homework files have been submitted today!
</div>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,68 @@
<?php
/*
* upload2usb.php
* Upload2USB App Helper Functions
*/
//return the first removable USB drive location
function getTargetUSBDriveLocation () {
// Get the first removal USB drive using
// lsblk --output NAME,TRAN,RM,MOUNTPOINT --pairs |grep RM=\"1\" | grep -v MOUNTPOINT=\"\" |grep -oP '[^/]MOUNTPOINT="\K[^"]*' -m 1
// lsblk --output NAME,TRAN,RM,MOUNTPOINT --pairs |grep RM=\"1\" | grep -v MOUNTPOINT=\"\" | cut -d " " -f 4 | cut -d "=" -f 2
$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')));
if (empty($removable_usb_path)) {
return "/library/www/html/local_content/";
} else {
return $removable_usb_path . "/";
}
}
//returns folder path where homework will be stored, if create_folder_p = 1, it will create the folder if it doesn't exist
function getTargetFolderPath ($create_folder_p) {
$parent_dir = getTargetUSBDriveLocation();
error_log("PARENTDIR: " . $parent_dir);
$today_folder_name = "UPLOADS." . date("Y-m-d");
$target_folder_path = $parent_dir . $today_folder_name;
if (!file_exists($target_folder_path) && $create_folder_p) {
mkdir($target_folder_path, 0777);
}
return $target_folder_path;
}
//return number of files within a specified folder
function getFileCount ($folder_path) {
return count(glob($folder_path . "/*"));
}
//*** TODO *** check file content to see if it's unique or not
function isFileContentUnique ($file) {
}
//*** TODO **** check if file exists based on file name and return unique name if does
function getUniqueFileName ($filename) {
}
// Check file size - we are not going to check file size for now.
// elseif ($_FILES["hw_submission"]["size"] > 5000000) {
// $upload_msg = "Your file is too large.";
// $upload_ok = 0;
// }
?>