Is it possible to read the type of file selected in an input field when on browsers (like IE8) that don't support javaScript FileReader?
I want to detect if the selected file is an image or not. I will have server side validation, but would also like the user to know if the file is correct before submitting. I've tried a number of different solutions but can't find any support for IE8...
This javascript doesn't work in IE8:
<input id="uploadImage" type="file"name="myPhoto" onchange="isImage();" />
var upload_image = document.getElementById("uploadImage");
function isImage() {
if (
upload_image.files[0].type == 'image/jpg' ||
upload_image.files[0].type == 'image/jpeg' ||
upload_image.files[0].type == 'image/png' ||
upload_image.files[0].type == 'image/gif' ||
upload_image.files[0].type == 'image/bmp'
) {
return true;
}
else return false;
}
This method doesn't help either:
function isImage(a){
return a.indexOf(".png") != -1 && a.type == file;
}
The 'accept' parameter also does not work in older IE versions:
<input name="img1" id="img1" type="file" accept="image" />