I searched the Internet and SO to understand this one of myself in different ways, but without success.
I would like to show a message if the file extension is accepted or not, the same as the instructions "outpush.push".
You need to do this from an array of accepted file extensions, such as JPG, PNG, GIF, and determine if the file extension is in upper case and accept it (convert it to lower case).
Here is my script. I wonder how and where in the script I could implement such a function?
function handleFileSelect(evt) {
var files = evt.target.files;
var max_size = 5120;
var output = [];
for (var i = 0, f; f = files[i]; i++) {
output.push('<li><strong><font size="3" color="FFFFFF">FILE: ', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
f.size, ' bytes, last modified: ',
f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',
'</font></li>');
if(f.size > max_size) {
output.push('<font size="5" color="FFFF00"><b>ERROR!! Sorry, but the file that you selected is too large. Please upload a file that is no larger than ' + max_size + ' KB.');
}
if(f.size < max_size) {
output.push('<font size="5" color="FFFF00"><b>FILE SIZE OK. CLICK TO SEND button below.</font>');
output.push('<font size="5" color="FFFFFF"><hr><b>IMPORTANT: Do not close this window. Wait till you see the next page when finished uploading your file.</font>');
document.getElementById("myButton").style.display="all";
}
}
document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
source
share