Javascript IE-9在使用输入类型文件时给出伪路径
我无法阅读IE-9中的文件。我正在从url生成base64。在除IE-9之外的所有其他浏览器中,它都可以工作。有人能帮我吗? 我在IE-9中获得了c://fakepath/images.jpgJavascript IE-9在使用输入类型文件时给出伪路径,javascript,internet-explorer-9,Javascript,Internet Explorer 9,我无法阅读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(); cons
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/*"/>
if((navigator.userAgent.indexOf(“MSIE”)!=-1)| |!!document.documentMode==true))//如果IE>10
{
tmppath=$(“#hi”).val();
控制台日志(“仅在ie中”+tmppath);
}
否则{
var selectedFile=this.files[0];
tmppath=URL.createObjectURL(event.target.files[0]);
console.log(“临时路径其他”+tmppath);
}
控制台日志(“临时路径”+tmppath);
您有针对IE9和更早版本的代码显式分支,并读取输入的值。type=“file”
输入的值总是有一个假路径(在所有浏览器上),因为不允许您知道文件的实际路径
另一个分支使用IE9不支持的createObjectURL
。(IE9一点也不支持这一点。)
您必须提交一个包含文件输入的表单,并处理文件服务器端