Display download link immediately after uploading file

This commit is contained in:
Andrew S. Rightenburg 2023-04-26 16:48:40 -04:00
parent 0099d1af32
commit 73f928232c
Signed by: rail5
GPG key ID: A0CB570AB6629159
4 changed files with 113 additions and 58 deletions

9
CHANGELOG Normal file
View file

@ -0,0 +1,9 @@
TODO
* Replace "sanitization" with SQL Prepared Statements
* General code clean-up
CHANGELOG
2023-04-26:
* Updated the upload page to display the file's download link immediately after uploading

View file

@ -1051,3 +1051,28 @@
body.is-ie #wrapper {
height: 100%;
}
#download-link {
display: -moz-flex;
display: -webkit-flex;
display: -ms-flex;
display: flex;
-moz-align-items: center;
-webkit-align-items: center;
-ms-align-items: center;
align-items: center;
-moz-justify-content: space-between;
-webkit-justify-content: space-between;
-ms-justify-content: space-between;
justify-content: space-between;
-moz-flex-direction: column;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-moz-perspective: 1000px;
-webkit-perspective: 1000px;
-ms-perspective: 1000px;
perspective: 1000px;
position: relative;
z-index: 2;
}

View file

@ -22,8 +22,10 @@ function deliverTop($pagetitle) {
<link rel="stylesheet" href="assets/css/main.css" />
<noscript><link rel="stylesheet" href="assets/css/noscript.css" /></noscript>
<style>
#settingsForm {
#settingsForm, #download-link {
display: flex !important;
align-items: center !important;
justify-content: center !important;
}
</style>
</head>

View file

@ -75,7 +75,26 @@ if ($uploadOk == false) {
echo "<div align='center'><h1>The file ". htmlspecialchars( basename( $_FILES["upfile"]["name"])). " has been uploaded.</h1></div>";
/* Provide the download link */
// We'll be using javascript to get the *absolute* link
echo "<script type=\"text/javascript\">
var downloadlink = window.location.href.slice(0, window.location.href.lastIndexOf('/')+1) + \"download.php?id=$newFileId\";
function copyToClipboard() {
navigator.clipboard.writeText(downloadlink);
}
function giveLink() {
let linkHTML = \"<input type='text' value='\" + downloadlink + \"' style='width: 40% !important;' disabled><div style='font-size: 5px !important;'>&nbsp;</div><button onclick='copyToClipboard()' style='background-color: rgba(255,255,255,0.3) !important; font-size: 18px !important;'><strong>Copy Link</strong></button>\";
document.getElementById(\"download-link\").innerHTML = linkHTML;
}
window.onload = giveLink;
</script>";
// Have a *relative* link accessible anyway in case the user has javascript disabled
echo "<div align='center' id='download-link' style='pointer-events: auto !important;'><a href='download.php?id=$newFileId'>Download Link</a></div>";
} else {
echo "<div align='center'><h1>Error uploading file</h1></div>";