From cef5cc12447dd6d6d49da69f9e54c48c5312cc88 Mon Sep 17 00:00:00 2001 From: Bartek Fabiszewski Date: Tue, 9 May 2017 22:48:17 +0200 Subject: [PATCH] Import: verify file size in browser --- js/main.js | 10 ++++++++-- lang/en.php | 1 + lang/pl.php | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/js/main.js b/js/main.js index bf085f4..688caae 100755 --- a/js/main.js +++ b/js/main.js @@ -222,7 +222,13 @@ function exportFile(type, userid, trackid) { window.location.assign(url); } -function importFile(input){ +function importFile(input) { + var form = input.parentElement; + var sizeMax = form.elements['MAX_FILE_SIZE'].value; + if (input.files && input.files.length == 1 && input.files[0].size > sizeMax) { + alert(sprintf(lang['isizefailure'], sizeMax)); + return; + } var xhr = getXHR(); xhr.onreadystatechange = function() { if (xhr.readyState == 4 && xhr.status == 200) { @@ -249,7 +255,7 @@ function importFile(input){ } // FIXME: show progress xhr.open("POST", "utils/import.php", true); - xhr.send(new FormData(input.parentElement)); + xhr.send(new FormData(form)); input.value = ""; } diff --git a/lang/en.php b/lang/en.php index 98a5aa5..8e24016 100644 --- a/lang/en.php +++ b/lang/en.php @@ -118,5 +118,6 @@ $lang["import"] = "Import track"; $lang["iuploadfailure"] = "Uploading failed"; $lang["iparsefailure"] = "Parsing failed"; $lang["idatafailure"] = "No track data in imported file"; +$lang["isizefailure"] = "The uploaded file size should not exceed %d bytes"; // substitutes number of bytes $lang["imultiple"] = "Notice, multiple tracks imported (%d)"; // substitutes number of imported tracks ?> diff --git a/lang/pl.php b/lang/pl.php index 2824596..7f81814 100644 --- a/lang/pl.php +++ b/lang/pl.php @@ -113,5 +113,6 @@ $lang["import"] = "Importuj trasę"; $lang["iuploadfailure"] = "Błąd przesyłania pliku"; $lang["iparsefailure"] = "Błąd parsowania pliku"; $lang["idatafailure"] = "Brak trasy w importowanym pliku"; +$lang["isizefailure"] = "Wielkość importowanego pliku nie może przekraczać %d bajtów"; $lang["imultiple"] = "Uwaga, zaimportowano kilka tras (%d)"; ?>