IE-9在使用输入类型文件时提供fakepath

IE-9 giving fakepath when using input type file

本文关键字:fakepath 文件 类型 输入 IE-9      更新时间:2023-09-26

我无法读取IE-9中的文件。我正在从url生成base64。在除IE-9之外的所有其他浏览器中,它都能正常工作。有人能帮我吗?我在IE-9 中得到了c:''//fakepath/images.jpg

if((navigator.userAgent.indexOf("MSIE") != -1 ) ||  !!document.documentMode == true )) //IF IE > 10
      {
      tmppath = $("#hi").val();
      console.log("only in ie"+tmppath);
      }
else{
    var selectedFile = this.files[0];
tmppath = URL.createObjectURL(event.target.files[0]);
console.log("temp path other"+tmppath);
}
console.log("temp path"+tmppath);
<input name="hello1" type="file" id="hi" accept="image/*"/>

您有针对IE9及更早版本的代码显式分支,并读取inputvaluetype="file" inputvalue总是有一个伪路径(在所有浏览器上),因为您不允许知道文件的实际路径。

另一个分支使用了IE9不支持的createObjectURL。(IE9根本不支持文件API。)

您必须提交一个包含文件输入的表单,并在服务器端处理文件。