-1
<!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>
上面的代碼的輸出是:如何獲取使用javascript上傳的文件夾的完整路徑名?
C:\ fakepath \文件名
FOLDERNAME
在這裏它顯示文件夾名和路徑名。它將默認值設置爲「假路徑」,但我需要找出確切的路徑!
糾正我,如果我錯了,但我不確定這是否可能使用JavaScript的安全目的。 – Script47