在各种浏览器中在javascript中读取客户端的文件内容
function getFileContents() { var fileForUpload = document.forms[0].fileForUpload; var fileName = fileForUpload.value; if (fileForUpload.files) { var fileContents = fileForUpload.files.item(0).getAsBinary(); document.forms[0].fileContents.innerHTML = fileContents; } else { // try the IE method var fileContents = ieReadFile(fileName); document.forms[0].fileContents.innerHTML = fileContents; }} function ieReadFile(filename) { try { var fso = new ActiveXObject("Scripting.FileSystemObject"); var fh = fso.OpenTextFile(filename, 1); var contents = fh.ReadAll(); fh.Close(); return contents; } catch (Exception) { return "Cannot open file :("; }}
getFileContents()
fileContents
在其他浏览器中有办法做到这一点吗?
编辑:
湖上湖
蝴蝶刀刀
一只甜甜圈