js获取文件路径,结果都是C:\fakepath的问题

2025-04-08 06:03:39

1、编写demo.htmldemo.html代码如下:<!DOCTYPE html><html><head>稆糨孝汶;<script type="text/script" src="demo.js"</script></head><body><input id="selectFileInput" type="file" multiple="multiple" list="fileList" /></body></html>

js获取文件路径,结果都是C:\fakepath的问题

2、编写demo.jsdemo.js代码如下://选择文件function selectFiles(e){ v锾攒揉敫ar tmpPath = this.value;//获取路径 if(!tmpPath){ return null; }else if(tmpPath.lastIndexOf('/') > -1){ return tmpPath.substring('0',tmpPath.lastIndexOf('/')); }else if(tmpPath.lastIndexOf('\\') > -1){ return tmpPath.substring('0',tmpPath.lastIndexOf('\\')); }}//页面加载事件window.onload = function(callback){ document.getElementById("selectFileInput").onchange = selectFiles;}

js获取文件路径,结果都是C:\fakepath的问题

3、获取路径和原因分析js获取文件路径为:“C:\fakepath”;原因分析:window系统为了安全考虑,不让从客户端获取文件路径,统一使用C:\fakepath代替。

js获取文件路径,结果都是C:\fakepath的问题
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢