在 Html 中选择文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35260416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Folder Choose in Html
提问by ozgursana
I just want users select folder path.
我只希望用户选择文件夹路径。
For example;
例如;
User choose 'D:/example/' folder.
用户选择“D:/example/”文件夹。
Then im save 'D:/example/' to my database.
然后我将 'D:/example/' 保存到我的数据库中。
<input type='file'> doesnt work for me . I just need folder path
How can i do that ?
我怎样才能做到这一点 ?
Edit: Everyone show this for answer
编辑: 每个人都展示这个答案
but this is not my question. It listing directory.
但这不是我的问题。它列出目录。
I just want folder path like d:/asd/ user pick asd folder on d.
我只想要像 d:/asd/ 这样的文件夹路径,用户在 d 上选择 asd 文件夹。
so i save my database to 'd:/asd/' .just this
所以我将我的数据库保存到 'd:/asd/' .just this
I dont know how can i explain more.
我不知道我该如何解释更多。
回答by Muhammet Demir
I hope this can help you
我希望这可以帮助你
you can see the folder name in alert when select a file
选择文件时,您可以在警报中看到文件夹名称
<script type="text/javascript">
function getfolder(e) {
var files = e.target.files;
var path = files[0].webkitRelativePath;
var Folder = path.split("/");
alert(Folder[0]);
}
</script>
<input type="file" id="flup" onchange="getfolder(event)" webkitdirectory mozdirectory msdirectory odirectory directory multiple />