Skip to content

Commit

Permalink
usb_lib/files/upload2usb/*: renaming app to Upload To USB instead of …
Browse files Browse the repository at this point in the history
…HW Submission, other minor cleanup/styling
  • Loading branch information
avni committed Jan 6, 2025
1 parent 2706381 commit 99ff433
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
14 changes: 7 additions & 7 deletions roles/usb_lib/files/upload2usb/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<html>

<head>
<title>IIAB Homework Submission App</title>
<title>IIAB Upload to USB App</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

Expand All @@ -31,16 +31,16 @@
<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>
<form action="upload-file.php" id="upload2usb_form" method="post" enctype="multipart/form-data">
<img class="mb-4" src="uk-swing.png" alt="" width="75">
<h1 class="h3 mb-3 font-weight-normal">Internet in a Box Upload to USB</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/>
<label for="upload2usb" style="font-weight:bold;padding-bottom:10px;">Upload your file here!</label>
<input type="file" name="uploaded_file" id="uploaded_file"><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!
<?php echo $file_count ?> files have been uploaded today!

</div>
</div>
Expand Down
16 changes: 8 additions & 8 deletions roles/usb_lib/files/upload2usb/upload-file.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

include("upload2usb.php");

//get folder path where homework will be stored
//get folder path where file will be stored
$target_folder_path = getTargetFolderPath(1);
$target_file = $target_folder_path . "/" . basename($_FILES["hw_submission"]["name"]);
$target_file = $target_folder_path . "/" . basename($_FILES["uploaded_file"]["name"]);
$upload_ok = 1;
$upload_msg = "";

if(!isset($_POST["submit"]) || empty(basename($_FILES["hw_submission"]["name"]))) {
if(!isset($_POST["submit"]) || empty(basename($_FILES["uploaded_file"]["name"]))) {
$upload_msg = "No file submitted.";
$upload_ok = 0;
} elseif (file_exists($target_file)) {
Expand All @@ -26,8 +26,8 @@

// 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!";
if (move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], $target_file)) {
$upload_msg = "&#x1F60A; &#x2705; Your file <span style=\"font-weight:bold; font-style:italic;\">". htmlspecialchars( basename( $_FILES["uploaded_file"]["name"])). "</span> was successfully uploaded!";
} else {
$upload_msg = "&#x274C; There was an error uploading your file. " . $upload_msg;
}
Expand All @@ -41,7 +41,7 @@
<html>

<head>
<title>IIAB Homework Submission App</title>
<title>IIAB Upload to USB App</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

Expand All @@ -57,9 +57,9 @@
<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>
<h1 class="h3 mb-3 font-weight-normal">Internet in a Box Upload to USB</h1>
<?php echo $upload_msg ?> <br/>
<?php echo $file_count ?> homework files have been submitted today!
<?php echo $file_count ?> files have been submitted today!

</div>
</div>
Expand Down
16 changes: 3 additions & 13 deletions roles/usb_lib/files/upload2usb/upload2usb.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,22 @@ function getTargetUSBDriveLocation () {
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
//returns folder path where file 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);

// 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
Expand All @@ -48,19 +41,16 @@ function getFileCount ($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) {
// elseif ($_FILES["uploaded_file"]["size"] > 5000000) {
// $upload_msg = "Your file is too large.";
// $upload_ok = 0;
// }
Expand Down

0 comments on commit 99ff433

Please sign in to comment.