From b46803b170624c10abf060c1d90e920f6d8e6be2 Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Mon, 30 Apr 2012 11:40:04 -0400 Subject: [PATCH] Adding sanity checks to verify file type and size Content-Type: text/plain; charset="utf-8" http://bugs.koha-community.org/show_bug.cgi?id=7977 --- .../prog/en/modules/tools/quotes-upload.tt | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes-upload.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes-upload.tt index ed8f80b..0ac5ae1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes-upload.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/quotes-upload.tt @@ -198,6 +198,7 @@ reader.onprogress = fnUpdateProgress; reader.onabort = function(e) { alert('File read cancelled'); + parent.location='quotes-upload.pl'; }; reader.onloadstart = function(e) { document.getElementById('cancel_upload').style.visibility="visible"; @@ -211,6 +212,22 @@ quotes = fnCSVToArray(e.target.result, ','); fnDataTable(quotes); } + + // perform various sanity checks on the target file prior to uploading... + var fileType = evt.target.files[0].type || 'unknown'; + var fileSizeInK = Math.round(evt.target.files[0].size/1024); + + if (fileType != 'text/csv') { + alert('Incorrect filetype: '+fileType+'. Uploads limited to text/csv.'); + parent.location='quotes-upload.pl'; + return; + } + if (fileSizeInK > 512) { + if (!confirm(evt.target.files[0].name+' is '+fileSizeInK+' K in size. Do you really want to upload this file?')) { + parent.location='quotes-upload.pl'; + return; + } + } // Read in the image file as a text string. reader.readAsText(evt.target.files[0]); } -- 1.7.0.4