解决IE不支持html5 file api中readAsBinaryString
//废话不多说,直接上源码 var reader = new FileReader(); reader.readAsBinaryString(fileData); reader.onload = function(e) { if (reader.result) reader.content = reader.result; var base64Data = btoa(reader.content); //... } //extend FileReader if (!FileReader.prototype.readAsBinaryString) { FileReader.prototype.readAsBinaryString = function (fileData) { var binary = ""; var pt = this; var reader = new FileReader(); reader.onload =...
js验证图片真实格式(针对手动修改后缀名)
js验证图片真实格式(针对手动修改后缀名) <input type="file" id="file" onchange="handleFiles(this.files)"/> <script> function handleFiles(files) { if (files.length) { var file = files[0]; console.log(file.name); console.log(getFileExt(file)); } } function getFileExt(file) { var index = file.name.lastIndexOf('.'); var fileExt = file.name.substring(index+1); return fi...