Accessing File Data of file input in IE8 on the cl

2019-07-18 20:19发布

问题:

Is it possible to get at the actual file data that is selected in a file input?

I'm trying to execute the following code and this.files does not contain the file data I was expecting (which does get there in Chrome).

document.getElementById('txtFileInput').onchange = function (event) {
                    //var files = event.target.files;
                    var files = this.files;
                    me.model.set('fileArray', files);
                };


<div class="fileInputContainer" style="display:none">
    <label for="txtFileInput">Edit file: </label>
    <input type="file" id="txtFileInput" class="txtFileInput"/>
</div>

Is there something I'm missing for IE or is it not possible?

回答1:

IE currently doesn't allow manipulation of the <input type="file"> element from JavaScript due to security reasons. Setting the filename or invoking a click event to show the browser dialog will result in an "Access is denied" error on the form submit. (IE is clever about remembering what methods have been invoked)

Please see this similar issue: http://www.webdeveloper.com/forum/showthread.php?t=181272



回答2:

@lkaradashkov explains that this isn't possible so I think what you're looking for is an HTML5 File API but unfortunately this is not available in IE until the upcoming IE10 release.