From 24d6fe6cdf095c032f76eb90f89cfc2de9af870a Mon Sep 17 00:00:00 2001 From: SuperDev Date: Thu, 22 Dec 2022 12:52:34 -0600 Subject: [PATCH] Update download.php --- download.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/download.php b/download.php index e789874..4d6adbe 100644 --- a/download.php +++ b/download.php @@ -68,7 +68,7 @@ if(isset($_POST['submit'])){ const fileLink = "' . $fileURL .'"; const initTimer = () => { if(downloadBtn.classList.contains("disable-timer")) { - return location.href = fileLink; + return downloadFile(filelink); } let timer = downloadBtn.dataset.timer; downloadBtn.classList.add("timer"); @@ -79,7 +79,7 @@ const initTimer = () => { return downloadBtn.innerHTML = `Your download will begin in ${timer} seconds`; } clearInterval(initCounter); - window.open(fileLink); + downloadFile(filelink); downloadBtn.innerText = "Your file is downloading..."; setTimeout(() => { downloadBtn.classList.replace("timer", "disable-timer"); @@ -88,5 +88,23 @@ const initTimer = () => { }, 1000); } downloadBtn.addEventListener("click", initTimer); + +public static downloadFile(url: string): void { + const xmlHttp = new XMLHttpRequest(); + xmlHttp.onreadystatechange = () => { + if (xmlHttp.readyState === 4 && xmlHttp.status === 200) { + const blobUrl = window.URL.createObjectURL(xmlHttp.response); + const e = document.createElement('a'); + e.href = blobUrl; + e.download = blobUrl.substr(blobUrl.lastIndexOf('/') + 1); + document.body.appendChild(e); + e.click(); + document.body.removeChild(e); + } + }; + xmlHttp.responseType = 'blob'; + xmlHttp.open('GET', url, true); + xmlHttp.send(null); + } '; ?>