HTML 4 equivalent of HTML 5's FileReader?

后端 未结 3 1229
甜味超标
甜味超标 2020-12-09 23:08

I\'ve got a web page which needs to be able to load files into the DOM from the local machine on which the browser is running. I\'ve found that this is very easy to do using

相关标签:
3条回答
  • 2020-12-09 23:40

    Further to the other answers here, it does appear that there's no consistent way of doing this client-side (other than Flash) for older browsers.

    For IE7/8 however, I've managed to hack something together using ActiveX.

    var filePath = f:\oo.txt;
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var textStream = fso.OpenTextFile(filePath);
    var fileData = file.ReadAll();
    

    I can then pass this to the same function as reader.onload in the question above. Obviously this is a bad, hacky solution, and liable to be blocked by some security policies - it does at least work for IE7 though!

    0 讨论(0)
  • 2020-12-09 23:51

    Looks like you can do that through Flash. Flash alternative for FileReader HTML 5 API

    0 讨论(0)
  • 2020-12-09 23:53

    No, you cannot do that in older browsers. FileReader (any file system access really) is a new HTML5 feature which is not supported in older browsers.

    Your best option in an older browser is either:

    1. A Silverlight, Flash or Java app (or similar) that runs on the client-side and has local file system access.
    2. Having the user upload files using the <input type="file"> element, and do your processing server-side.
    0 讨论(0)
提交回复
热议问题