gpt4 book ai didi

javascript - 带有显示完整路径的文本框的文件选择器

转载 作者:行者123 更新时间:2023-12-02 19:17:29 25 4
gpt4 key购买 nike

如何显示一个文本框和一个选择文件图标,并且当选择文件时,它将在文本框中显示文件的完整路径(无假路径)?

<input type="file">似乎只显示文件名,没有完整路径。

最佳答案

隐藏完整路径的决定是出于隐私和安全问题。

根据working draft of the HTML5 specificationvalue属性:

must return the string "C:\fakepath\" followed by the filename of the first file in the list of selected files, if any, or the empty string if the list is empty.

因此,除了使用 Java 或 Flash 小程序之外,可能无法通过 JavaScript 或任何其他方式获取完整路径。 (Java和Flash都不是标准的,所以我认为你不会喜欢它)。我想说你最好坚持标准<input type="file" />大多数桌面和移动浏览器都支持。

<小时/>

进一步说明:根据WHATWG,返回假路径而不仅仅是文件名的原因:

The original plan was to just have the filename. Unfortunately, it turns out that if you do that, there are certain sites that break, because they expect the path (and they expect a Windows path, no less). This is why Opera and IE8 return a fake path -- not because HTML5 says to do it. In fact I made HTML5 say it because they were doing it.

关于javascript - 带有显示完整路径的文本框的文件选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12959932/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com