diff --git a/front.php b/front.php
index 38e98c7..7e3d66b 100644
--- a/front.php
+++ b/front.php
@@ -22,12 +22,15 @@
File Transfer
-Drag and Drop your file or
-
-
-
(Maximum )
-
-
+
Drag and Drop your file or
+
+
(Maximum )
+
+
+
This tool is usable with curl or wget.
diff --git a/script.js b/script.js
index 70e90b9..2a48d30 100644
--- a/script.js
+++ b/script.js
@@ -28,30 +28,69 @@ function copytoclipboard()
document.execCommand("Copy");
}
-function upload_file(file_obj,file_name)
+function upload_file(file_obj, file_name)
{
- var divresponse = document.getElementById('divresponse');
- divresponse.innerHTML = "Uploading file..." ;
+ const divresponse = document.getElementById('divresponse');
+ divresponse.innerHTML = "Uploading file...";
+
+ const copyToClipboard = document.getElementById('copytoclipboard');
+ copyToClipboard.style.visibility = "hidden";
+
+ const progressContainer = document.getElementById('progress-container');
+
+ // Update progress bar
+ const progressBar = document.getElementById('progress-bar');
+ progressBar.value = 0;
+ const progressText = document.getElementById('progress-text');
+ progressText.innerText = "0%";
+ progressContainer.style.display = ''; // <- become visible by style
+
const request = async () => {
- var response = await fetch('/index.php?name=' + file_name, {
- method: 'PUT',
- body: file_obj
+ // Create XMLHttpRequest for progress tracking
+ const xhr = new XMLHttpRequest();
+
+
+ // Track upload progress
+ xhr.upload.addEventListener('progress', function(e) {
+ if (e.lengthComputable) {
+ const percentComplete = Math.round((e.loaded / e.total) * 100);
+
+ if (progressBar && progressText) {
+ progressBar.value = percentComplete;
+ progressText.innerText = percentComplete + '%';
+ }
+ }
});
- var text = await response.text();
- divresponse.innerHTML = text ;
- document.getElementById('copytoclipboard').style.visibility = "visible";
-
- if (text.startsWith("http")) {
- var fturl = document.getElementsByTagName("fturl");
- Array.from(fturl).forEach(tag => tag.innerHTML = text);
- }
-
+
+ // Handle completion
+ xhr.addEventListener('load', function() {
+ if (xhr.status === 200) {
+ divresponse.innerHTML = xhr.responseText;
+ progressContainer.style.display = 'none';
+ copyToClipboard.style.visibility = 'visible';
+
+ if (xhr.responseText.startsWith("http")) {
+ var fturl = document.getElementsByTagName("fturl");
+ Array.from(fturl).forEach(tag => tag.innerHTML = xhr.responseText);
+ }
+ } else {
+ divresponse.innerHTML = "Upload failed. Please try again.";
+ }
+ });
+
+ // Handle errors
+ xhr.addEventListener('error', function() {
+ progressContainer.style.display = 'none';
+ divresponse.innerHTML = "Upload failed. Please try again.";
+ });
+
+ // Setup and send request
+ xhr.open('PUT', '/index.php?name=' + encodeURIComponent(file_name));
+ xhr.send(file_obj);
}
request();
-
}
-
function change_color_ondrag(event)
{
if (event === "ondragenter")
@@ -65,4 +104,3 @@ function change_color_ondrag(event)
element.classList.remove("dragover");
}
}
-
diff --git a/style.css b/style.css
index cc262b8..ded28ff 100644
--- a/style.css
+++ b/style.css
@@ -34,6 +34,10 @@ h1 {
}
.dragndrop {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 8px;
margin-top: 5%;
margin-bottom: 3%;
background-color: #a3a3a3;
@@ -63,6 +67,24 @@ h1 {
padding: 10px;
}
+#progress-container {
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+
+ width: 80%;
+ border-radius: 5px;
+ margin-top: 10px;
+}
+#progress-bar {
+ position: relative;
+ width: 100%;
+ height: 20px;
+ background-color: #eeeeee;
+ border-radius: 5px;
+ transition: width 0.3s;
+}
+
footer {
position: absolute;
padding-top: 10px;