javascript 在Firefox中以html格式上传文件时获取文件完整路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9463368/
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
Getting file full path when uploading file in html in firefox
提问by user1232780
I want to get the full file path when uploading a file.
我想在上传文件时获取完整的文件路径。
. If we use safari or IE browser i am getting full file path but in firefox it is not working
. 如果我们使用 safari 或 IE 浏览器,我将获得完整的文件路径,但在 firefox 中它不起作用
how can i get the full file path name by using javascript or jquery in firefox.
我如何通过在 Firefox 中使用 javascript 或 jquery 来获取完整的文件路径名。
Thanks
谢谢
回答by mpm
You cant, for security reasons. the broswer knows nothing about the user's hard drive.
你不能,出于安全原因。浏览器对用户的硬盘一无所知。
回答by Christian
I can't imagine why anyone would want this kind of feature in the first place. You are uploading files, not specifying your hard disk structure. If this is for a legitimate reason, simply show a text box next to the uploader asking for the local path.
我无法想象为什么有人会想要这种功能。您正在上传文件,而不是指定您的硬盘结构。如果这是出于合法原因,只需在上传者旁边显示一个文本框,询问本地路径。
回答by prieston
You can actually for example if you want to load an image with full path you can use a code like:
例如,您实际上可以使用完整路径加载图像,您可以使用如下代码:
<html>
<body>
<img src = "file:///C:/Users/UserName/Folder1/Folder2/image.jpeg" />
</body>
</html>
So in a program you could ask the user to copy-paste the full path in a textbox and you can add the "file:///" after to read the file from the browser. If you drag and drop a file to the browser you will see how the browser reads its path.
因此,在程序中,您可以要求用户将完整路径复制粘贴到文本框中,然后添加“file:///”以从浏览器读取文件。如果将文件拖放到浏览器,您将看到浏览器如何读取其路径。
This answer is useful for someone who wants to make an offline application running on browsers client side only. This example was tested in Firefox and not sure if this is valid anymore.
这个答案对于只想在浏览器客户端运行离线应用程序的人很有用。此示例在 Firefox 中进行了测试,不确定这是否不再有效。