I have searched the Web and SO to figure this one out by myself with many different ways, but with no success.
I would like to show a message if the file extension is accepted or not, in the same fashion as the "outpush.push" statements.
This would need to be taken from an ARRAY of accepted file extensions such as JPG, PNG, GIF and detect if the file extension is uppercase and accept it (convert it to lowercase).
Here is my script. Am wondering how and where in the script could I implement such a feature?
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
var max_size = 5120; // Max file size
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);
if(f.size > max_size)andif(f.size < max_size). The second should just be anelsestatement. Also, iff.size == max_size, you won't get any message.