<!DOCTYPE html>
<html>
<body>
<div align="center" style="width:800px" >
LocalShare:
<input type="file" id="FileUpload" onchange="selectFolder(event)" webkitdirectory mozdirectory multiple />
<p id="demo"></p>
<p id="demo1"></p>
<script>
function selectFolder(e) {
var txt = "";
var theFiles = e.target.files;
var relativePath = theFiles[0].webkitdirectory;
var relativePath = theFiles[0].webkitRelativePath;
var x = document.getElementById("FileUpload").value;
document.getElementById("demo").innerHTML = x;
document.getElementById("demo1").innerHTML = relativePath;
var folder = relativePath.split("/");
alert(folder[0]);
}
</script>
</body>
</html>
以上代码的输出是:
C:\ fakepath \文件名
文件夹名
此处显示文件夹名称和路径名称。它将默认值视为“fakepath”,但我需要找出确切的路径!
答案 0 :(得分:1)
嗯,早些时候它被允许但是由于安全原因浏览器不允许我们获取客户端机器的内部细节。