Import: verify file size in browser

This commit is contained in:
Bartek Fabiszewski 2017-05-09 22:48:17 +02:00
parent b62b0b9b29
commit cef5cc1244
3 changed files with 10 additions and 2 deletions

View File

@ -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 = "";
}

View File

@ -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
?>

View File

@ -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)";
?>