I'm trying to get a local file from a system, I did some searching and came around a way of doing this, when I tried to implement it in my code, I got the error:
Uncaught TypeError: Cannot read property 'type' of undefined
document.getElementById('add-new-cat').addEventListener('click', handleFileSelect, false);
function handleFileSelect(evt) {
var files = evt.target.files;
if(files.type.match('image.*')) {
var reader = new FileReader();
reader.onload = (function(theFile) {
})(files);
var catIMG = reader.readAsBinaryString(files);
alert(catIMG);
}
}
<input type="file" name="cat_path_orig" id="cat-path-orig">
<button class="btn btn-primary" id="add-new-cat">add</button>
I wouldn't know how to trigger the function with the file included, because I know it's looking for a value in the button that's being clicked